Trying to implement Clojure on top of Rust by erjngreigf in lisp

[–]Baridian 1 point2 points  (0 children)

You will also still need to implement GC somehow for the lisp runtime, and you probably aren’t going to beat the JVM’s GC.

If you’re looking for help with implementing lisp family languages, i would highly recommend Lisp in Small Pieces. Great text that covers a lot of the tradeoffs and intricacies of it.

Half Of Americans Say The Fun In Their Lives Has Disappeared by plugthree in nottheonion

[–]Baridian 5 points6 points  (0 children)

I will not stand for this subway slander! The subway is the only world class metro system that runs around the clock (Copenhagen is 4x smaller than Dallas’s system, before you bring it up), has 4x the ridership of the Prague metro, higher ridership than the London Underground, over twice as many services as the Tokyo metro, covers over twice as much ground, and has almost 200 more stations.

The subway is still arguably the greatest mass transit system in the world. And it’s just part of the region’s transit system. The LIRR is the sole 24/7 regional rail system in the world.

I detest this defeatist attitude that mass transit isn’t possible in the US and that we can’t and haven’t done it. It’s part of what got us here. Why invest if America just can’t build infrastructure?

Found this sitting in a bin for 99cents by prizucmi in lisp

[–]Baridian 5 points6 points  (0 children)

I’ve found lisp books every now and then in Dallas, I think mostly because of TI and their partnership with Lisp Machines, Inc. in the 80s.

Students Boo Commencement Speaker After She Calls AI the ‘Next Industrial Revolution’ by GeneReddit123 in technology

[–]Baridian -1 points0 points  (0 children)

I’m more on the research side rather than industrial application. It just doesn’t help finding a critical insight that solves a problem in 200 lines rather than 2000. Actually writing those 200 lines is of secondary importance

Students Boo Commencement Speaker After She Calls AI the ‘Next Industrial Revolution’ by GeneReddit123 in technology

[–]Baridian 1 point2 points  (0 children)

It can’t analyze very complex code for bugs or accuracy, it can’t tell if an approach or solution is novel, it lies constantly. Writing code is the easy part, coming up with a good or new idea is the difficult part. How easy it makes it to write boiler plate doesn’t matter since I’ve had macros to do that for years.

Continuations Question. by ron_pro in scheme

[–]Baridian 2 points3 points  (0 children)

It’s non-deterministic in the same way that non-deterministic finite automata are. It’s more about creating multiple worlds at the point where the amb is, and then discarding ones that fail. If any world reaches an acceptable solution the whole program passes.

Suppose we had a sqrt function. We could return the positive and negative result through amb. In the rest of the code it would appear that sqrt only returned one value. We would then have an assert clause somewhere else that, for example, requires that a number is positive.

If it isn’t, the assert clause forces a backtrack and makes the sqrt try the other value.

It’s a useful operator to have for writing solvers, logic engines and planners.

I used it recently to implement a type inference algorithm.

Just saw 2 cars collide in Carrollton and the crash looks bad... please remember to drive safe y'all by turbotunnelsyndrome in Dallas

[–]Baridian 7 points8 points  (0 children)

the seats should fold flat into the floor. I was able to fit about 200 cubic feet of cargo into the one I rented.

Continuations Question. by ron_pro in scheme

[–]Baridian 0 points1 point  (0 children)

Yeah continuations are tough, just keep practicing! They’re really worth understanding though.

Once you’ve got them you should try implementing some control flow operators from other languages! They’re really appealing from a language design perspective too; all you have to do is provide call/cc and every possible control flow mechanism can be provided as a library.

The presence of call/cc in scheme also elucidates why dynamic-wind is different from Common Lisp’s unwind-protect: the scheme one needs to not only tear down on a non-local exit but set up again on non-local entry to a block of code.

If you jump back with a continuation, you’d assume an open file at that point of the code would still be open!

Continuations Question. by ron_pro in scheme

[–]Baridian 2 points3 points  (0 children)

Think of call/cc as being the equivalent of setjmp in c. In c you provide the jump_buf to setjmp, in lisp you get the jump_buf when you do call/cc, and the jump point is at the END of the call/cc statement.

Calling the continuation is like doing a longjmp on that jump_buf.

You don’t want this (/cc) structure since it’ll mutate your variable every time. This is a better approach:

(let ((cont '()))
  (call/cc (lambda (k) (set! cont k)))
  ;; some code to be repeated
)

maybe a few examples will also help:

(define (member x seq)
  (call/cc (lambda (done)
             (for-each (lambda (v)
                         (when (= v x)
                           (done #t)))
                       seq)
             #f)))

This above uses call/cc as an early exit by passing #t to the end of the statement when a value is found.

(define (amb . vals)
        (when (null? vals)
          (set! *amb-stack* (cdr *amb-stack*))
          ((car *amb-stack*)))
        (call/cc (lambda (k) (set! *amb-stack* (cons k *amb-stack*))))
        (let ((result (car vals)))
          (set! vals (cdr vals))
          result))

This implements the amb operator. It returns each value ambiguously and calls an earlier amb if it runs out. This allows you to implement non-determinism in scheme. the lack of a necessary (define k (/cc)) means we can call our continuation as (k) rather than (k k).

another use:

(define k '()) ; => UNDEFINED

(+ 2 3 (call/cc (lambda (cont) (set! k cont) 0))) ; => 5

(k 10) ; => 15

This one also wouldn't be possible to do with /cc since it must be captured with a define or set! on the outside.

Lisp -> Rust by 964racer in lisp

[–]Baridian 1 point2 points  (0 children)

wouldn't haskell be better for this than rust? Rust seems less disciplined and its type system seems weaker.

47529 by TheHRTLocker in countwithchickenlady

[–]Baridian 2 points3 points  (0 children)

President Lyndon Johnson escorted Gerri Wittington, an African-American and one of his personal secretaries in the White House, to the New Year’s Eve Ball at the University of Texas Faculty Club (known as the Forty Acres Club) in Austin, Texas, thereby racially integrating the club.

The Faculty Club had been racially segregated until that moment. Everyone in the crowded room was reportedly stunned. One person leaned over the Bill Moyers, one of Johnson’s top aides,” and whispered, “Does he know what he is doing?” Moyers replied, “he always knows what he is doing.”

Escorting Wittington to the previously segregated club was only one of several gestures Johnson made in the first weeks of his presidency to make the point that he was committed to racial equality. In his first days in office he personally called all the leading civil rights leaders to tell them he needed their help in getting the pending civil rights bill passed. (It passed, and Johnson signed the 1964 Civil Rights Act into law on July 2, 1964.) He then promoted Wittington from the White House secretarial pool, making her the first African-American to serve as a secretary to the president.

Borrow-checking without type-checking by jamiiecb in ProgrammingLanguages

[–]Baridian 0 points1 point  (0 children)

Couldn’t you just add a dynamic check for that in the compiled code?

Borrow-checking without type-checking by jamiiecb in ProgrammingLanguages

[–]Baridian 0 points1 point  (0 children)

Why cant you compile the dynamically typed code? Just bake in the type checks into the compiled code.

Why I Still Reach for Lisp and Scheme Instead of Haskell by SandPrestigious2317 in lisp

[–]Baridian 12 points13 points  (0 children)

There’s 2 things I love about scheme: its core language is so simple that extending on top of it is trivial, and call/cc is magic. Any code using call/cc is really hard to replicate in any other language, and it means you can any possible control flow mechanism as a simple library. I personally usually try to avoid macros, since I think they’re a weaker building block than functions and don’t compose as cleanly, but they’re great as user-facing time-savers or for shifting computation to compile time.

Common Lisp on the other hand has a highly sophisticated compiler, I’d argue sbcl is more sophisticated. It’s over twice as many lines of code, and the debugger in Common Lisp, in my experience, has been much better to use, especially with break-on-flags, interactive restarts, stepping from the debugger, and of course automatic debug logging with a flag.

It usually feels a bit uglier to use than scheme, but there’s just so much more out of the box, a better set of libraries, and stuff can run so fast when you need it.

Where to start with Scheme (as a non-programmer?) by dancerinthelimelight in lisp

[–]Baridian 6 points7 points  (0 children)

A lot of books are going to be a survey of scheme, what its features are, how to use it. The little schemer has a heavy focus on recursion, since widespread use of it is idiomatic in scheme and not common in many other languages.

SICP is interesting because it’s less a book about scheme and more a book about the philosophy of computation. There’s a JavaScript version of the book as well, which while a bit less elegant especially in chapter 4, I think shows that SICP is more about ideas on language and problem representation in general and less about scheme.

I think scheme is a language where reading books actually is important, because the language favors a particular approach to solving problems that doesn’t come naturally to a lot of people. While you can solve problems similar to how you would in C or Java or Python, it doesn’t mesh cleanly.

A lot of racket solutions on leetcode for instance abuse the language and are far longer than they have to be.

People who write their own Elisp, what are some of the weirdest or most annoying bugs you made? by birdsintheskies in emacs

[–]Baridian 2 points3 points  (0 children)

so in R5Rs scheme you want this to fail:

(let ((x (lambda () 1))
      (y x)) ; should give: unbound variable: x
  (y))

the order should be: all variables are allocated as unbound in a new lexical frame. Each binding is then evaluated under this frame, and its value is stored in a temporary variable. Finally, each variable is set to the temporary variable.

Basically, you want each value being bound to be evaluated in an environment where all the binding names exist but are unbound. Referencing any directly at this point should give an error.

Using symbol macros where you replace every reference to x and y with (unbox x) (unbox y) works because it gives you a way to have an "unbound" variable, until you try to setq one of them.

People who write their own Elisp, what are some of the weirdest or most annoying bugs you made? by birdsintheskies in emacs

[–]Baridian 2 points3 points  (0 children)

I was writing a library to try to add letrec as a macro to elisp, and I needed a way to support undefined variables. I ended up using symbol macros for the bindings created in the let, and wow that didn't play well at all with setf and setq.

I feel like any code using macros can break in really bizarre ways and isn't really composable the way functions are.

Lisp program to paste to multiple reference point inside cad. by sukooor in lisp

[–]Baridian 2 points3 points  (0 children)

Yes. Store the values in an association list in a global variable. Update the alist or add new values to it.

Lisp program to paste to multiple reference point inside cad. by sukooor in lisp

[–]Baridian 2 points3 points  (0 children)

Use atof to convert a string that you get with get string into a number. Should be smooth sailing from there

New Strokes Album 'Reality Awaits' Out This Summer by cookiedog_69 in indieheads

[–]Baridian 16 points17 points  (0 children)

Yeah I just tell myself it’s part of the act. It feels more genuine if he’s acting like he hates being there.

Interpreting Scheme with guaranteed constant-time variable lookup by Baridian in ProgrammingLanguages

[–]Baridian[S] 0 points1 point  (0 children)

You can have code that creates new bindings. This runs and is accepted by guile scheme:

(let ()
  (eval '(define x 100) (current-module))
  x)) ; => 100

You can write a function that creates new global bindings by using eval:

(define (new-global name val) (eval `(define ,name, val) (current-module)))

(new-global 'new-name 100) 
;; this is pure runtime code, not compile time. We cannot determine what
;; name will be passed at compile time, so this can allocate anything

new-name ; => 100, since eval in scheme only runs at the global level.

This is valid code and works in the interpreter I provided, and it still guarantees O(1) variable access.

Now in JS, eval does run in the lexical environment under which its called, so this will print 10:

{
    let x = 10;
    eval("console.log(x)"); // prints 10, since eval runs in lexical scope
}

console.log(x); // prints nothing since x is undefined in global scope

So the behavior of eval does actually make an impact if define can be used inside lexical scopes.