Live data from Hacker News

Perchance to Scheme (2016)

hardmath123.github.io

71–80 of 82 posts

Re: Perchance to Scheme (2016)

#71
post #49

Earlier quoted context omitted.

> a big difference that Common Lisp brings to the table is that it has separate namespaces for variables and functions. This may not sound like much but it makes it much easier to write macros (code that writes code) and facilitates compile-time computing. A little more detail here: it has a lot more namespaces than that. Indeed, you can attach arbitrary different namespaces of things to symbols if you want to. It tu…

> A little more detail here: it has a lot more namespaces than that. And I don't think the function/value split is even the most important namespacing it does with regards to macro hygiene ("functions are less likely to be shadowed" always struck me as a kind of weak argument). Symbols being namespaced under packages is a much more robust solution: CL-USER> (defmacro m (x) `(car ,x)) M CL-USER> (defpackage :p) # CL-U…

The problem is that it is quite common for cl:car to be accessible in packages, because of the practice of use-ing the cl package everywhere.

Even if I'm in my own package, I can't do this:

  (flet ((car (x) ...)))
    (m arg))
because in order to have a hassle-free Lisp coding experience in my package, I brought in all the public symbols from the common-lisp package. So my flet is in fact shadowing cl:car.

Even if I just import the specific common-lisp things I need, and car is not one of them, that could change. Today, that car above is mypkg:car. Tomorrow, someone edits the defpackage to import car (because they needed it in a function they added), and now when that file is re-read, car is cl:car.

Packages have a theoretical solution to the hygiene problem that will not be air-tight in practice due to use/importation.

Another problem is that programmers aren't going to define a large number of packages to protects parts of their program from each other. A common practice is just to make one package for an entire project.

You need fine-grained package use to achieve near perfect hygiene. Ideally, each module that provides macros should have its own package, and use only symbols from that package in the macro expansion. If module A uses a macro from package B, and that macro generates a local function F, that will be B::F, not interfering with the A::F function. If the modules are in the same master project package, the clash is not averted, obviously.

Re: Perchance to Scheme (2016)

#72

Alternatively - you can choose to program in Common Lisp - an industrial strength language that has been demonstrated in large projects like the QPX flight search engine (Google Flights). For anyone who doesn't know - a big difference that Common Lisp brings to the table is that it has separate namespaces for variables and functions. This may not sound like much but it makes it much easier to write macros (code that…

>much easier to write macros (code that writes code) and facilitates compile-time computing Isn't this a non-issue in scheme as it has hygienic macros? Note: my only exposition to lisp is via elisp, so I might not know what I'm talking about.

Most CLers hate scheme macros since they almost uniformly believe that syntax-rules is the only macro facility. I myself have implemented defmacro using syntax-case because it is sometimes nice to have.

Hygiene solves the issue of namespacing macros, but at the cost of a very complex implementation. Implementing hygiene is HARD and I don't think it can even be called a solved problem. The current systems have issues that have proven to be hard to resolve.

Re: Perchance to Scheme (2016)

#73
post #70

Earlier quoted context omitted.

Look at things like: (define lst '(4 5 6)) (set! (car lst) 3) (display (car lst)) ;; 3 That's a pretty serious semantic departure. It's at least as different from RnRS as Racket, which insists it is not Scheme.

There's an SRFI for generalised set! that lots of implementations (Racket, Guile, Chicken, etc) support: https://srfi.schemers.org/srfi-17/srfi-17.html

Neat. Learn something new every day.

Re: Perchance to Scheme (2016)

#74
post #70

Earlier quoted context omitted.

There's an SRFI for generalised set! that lots of implementations (Racket, Guile, Chicken, etc) support: https://srfi.schemers.org/srfi-17/srfi-17.html

Neat. Learn something new every day.

It's not in widespread use though.

Re: Perchance to Scheme (2016)

#75

Earlier quoted context omitted.

Umm superficially you could say it is anything. The reality is it IS Scheme. (define (foo bar) (format "hi ~a" bar)) works just fine. As will any of the Scheme code, as it's merely syntactic sugar, (import :std/sugar) that you are confusing with a whole new language.

Look at things like: (define lst '(4 5 6)) (set! (car lst) 3) (display (car lst)) ;; 3 That's a pretty serious semantic departure. It's at least as different from RnRS as Racket, which insists it is not Scheme.

I was requesting valid scheme that did not work properly. Given the https://ecraven.github.io/r7rs-benchmarks/ shows Gerbil passing more tests than many other implementations, it seems hard to call it a "non-scheme".

Re: Perchance to Scheme (2016)

#76
post #72

Earlier quoted context omitted.

>much easier to write macros (code that writes code) and facilitates compile-time computing Isn't this a non-issue in scheme as it has hygienic macros? Note: my only exposition to lisp is via elisp, so I might not know what I'm talking about.

Most CLers hate scheme macros since they almost uniformly believe that syntax-rules is the only macro facility. I myself have implemented defmacro using syntax-case because it is sometimes nice to have. Hygiene solves the issue of namespacing macros, but at the cost of a very complex implementation. Implementing hygiene is HARD and I don't think it can even be called a solved problem. The current systems have issues…

That's intersting, because the lisp 'the right thing' approach [1] calls for correctness and ease of use over simplicity of implementation.

[1] as opposed to the alledged 'worse is better' of the unix world.

Re: Perchance to Scheme (2016)

#77
post #5

I know this is a big controversial can of worms, but as a filthy casual who just happens to like Lisp, the idea of R6RS is pretty appealing to me. This post seems very much R5RS-oriented. Are there any R6RS-conformant Schemes that are recommended?

Racket has an official R5RS and an official R6RS modes (you must start your program with #lang r6rs or with #!r6rs) and also an unofficial R7RS mode.

Re: Perchance to Scheme (2016)

#78
post #72

Earlier quoted context omitted.

>much easier to write macros (code that writes code) and facilitates compile-time computing Isn't this a non-issue in scheme as it has hygienic macros? Note: my only exposition to lisp is via elisp, so I might not know what I'm talking about.

Most CLers hate scheme macros since they almost uniformly believe that syntax-rules is the only macro facility. I myself have implemented defmacro using syntax-case because it is sometimes nice to have. Hygiene solves the issue of namespacing macros, but at the cost of a very complex implementation. Implementing hygiene is HARD and I don't think it can even be called a solved problem. The current systems have issues…

> uniformly believe that syntax-rules is the only macro facility

far from it. CLers know that Scheme has zillions of different macro systems. Which makes the whole topic highly confusing and intellectually interesting.

Re: Perchance to Scheme (2016)

#79
post #78
post #72

Earlier quoted context omitted.

Most CLers hate scheme macros since they almost uniformly believe that syntax-rules is the only macro facility. I myself have implemented defmacro using syntax-case because it is sometimes nice to have. Hygiene solves the issue of namespacing macros, but at the cost of a very complex implementation. Implementing hygiene is HARD and I don't think it can even be called a solved problem. The current systems have issues…

> uniformly believe that syntax-rules is the only macro facility far from it. CLers know that Scheme has zillions of different macro systems. Which makes the whole topic highly confusing and intellectually interesting.

What I meant by that is that CLers usually complain about hygiene as if it was impossible to break. I don't know how many times I have had to explain that syntax-rules is the high level macro facility and that all schemes provide their own lower level macro facility, be it explicit/implicit renaming (chicken), syntax-case (r6rs) or syntactic closures (Chibi?).

I understand the complaint that this isn't portable. It isn't. R6RS tried to standardise it. Hopefully r7rs does better in that regard.

Re: Perchance to Scheme (2016)

#80
post #72

Earlier quoted context omitted.

Most CLers hate scheme macros since they almost uniformly believe that syntax-rules is the only macro facility. I myself have implemented defmacro using syntax-case because it is sometimes nice to have. Hygiene solves the issue of namespacing macros, but at the cost of a very complex implementation. Implementing hygiene is HARD and I don't think it can even be called a solved problem. The current systems have issues…

That's intersting, because the lisp 'the right thing' approach [1] calls for correctness and ease of use over simplicity of implementation. [1] as opposed to the alledged 'worse is better' of the unix world.

It is a matter of preference. Sometimes you end up using gensym in scheme as well, especially for introducing identifiers in bulk.
Post reply on HN