I teach Scheme and Python on different contexts, to middle and high school students with varying degrees of programming background (beginner to ~fairly advanced), and wanted to share what I perceive kids to struggle with when learning Scheme relative to other languages, and how I think some of these changes might help (or hurt) my students.
- Kids struggle with parentheses, but they also struggle with car and cdr (first and rest), the notion of an expression, the difference between a symbol and a string, recursion (obvious) etc. Parenthesized syntax isn't special in this regard. - Many constructs in Python, however, pose just as much trouble (the off-sides rule is a big one, especially if they have prior exposure to curly braces syntax), including pretty pedestrian stuff like the difference between a string literal and a variable name, or the difference between defining and calling a function. - Whether or not students have prior programming experience they tend to bring in assumptions about what programming is supposed to look like, and s-expressions are quite contrary to that. However, they are not *especially* difficult to learn, relative to other programming constructs. - I think a lot of complaints about s-expressions come from people who understand themselves as competent programmers but struggle with a language that works very unlike anything they've encountered before (it works the same in reverse; I learned lisp first, and still frequently write buggy python code that looks like `map(lambda x: x + 1, some_list.sort())`). - I think minimizing parentheses would probably make for more readable code and would probably help my students, but it would do so primarily by not looking so ostentatiously different than what people are used to; people would be slower to assume they don't have any idea about what's going on. - On the other hand, parenthesized syntax is a natural way of conveying the difference between statements and expressions, and that's lost in moving away from parenthesized syntax, so there's some trade-off there. On Sunday, July 14, 2019 at 1:44:30 PM UTC-4, cwebber wrote: > > The context of this email is the proposal by Matthew Flatt that we move > to an easier-to-accept surface syntax for #lang racket2. > > Matthew Flatt has heard more than enough from me of concern about this > proposal. But I should indicate that I'm highly sympathetic to the > goal. I would like to lay out the following observations: > > - The challenge with s-expressions is largely in anxiety with something > that looks extremely alien. I suspect there's more fear from > instructors than students in encountering a lisp syntax; my > experience is that introducing someone who doesn't know differently > to a parenthetical syntax isn't scary for them, and they tend to like > it. But people who have *started out* with experience in a non-lispy > language tend to find it scary. > > - Nonetheless, assumptions that various math operators should be infix > is understandable because that's what people see today. > > - I am indeed very for growth in the community, though my main interest > in growth is in seeing a wider diversity of participants than just > raw numbers. Obviously other peoples' mileage may vary. > > - We are at serious risk in this pivot of losing some key things: > > - Many communities I have been in that have undertaken such a large > pivot to increase popularity expend enormous energy in the move to > the new thing, and in that process, the project actually collapses. > What I'm trying to say is that a pivot is a gamble; we should > calculate our odds carefully. (Indeed, the first thing I thought > when I heard that this might happen was, did I make a mistake in > shifting my work to Racket? It is unlikely I would have come to > Racket if there wasn't an equivalent amount of elegance.) > > - I'm not sure if I could have understood Racket Week with a syntax > that didn't have the elegance of s-expressions. This is not to say > that *no* syntax can have that level of elegance where things can > be so clear, however. > > IIRC Matthew's proposal for "#lang racket2" was something like the > following: > > a) function(args ...) should work. > b) infix is necessary for math, such as 3 + 4 > c) parentheses should be possible for grouping > > The weird thing about the last one being that this is already kind of > true in s-expressions, but by ~default this also results in application. > > Let me add one more suggested design goal: > > - the new syntax should must not be significantly less elegant than > s-expressions. > > Is there a way to achieve this? I actually think the best path forward > is to have a surface syntax that actually maps completely to > s-expressions, which is in fact universal that it can work with *any* > s-expression syntax. > > I would suggest starting with Wisp as the basis for examining this: > > https://dustycloud.org/blog/wisp-lisp-alternative/ > https://srfi.schemers.org/srfi-119/srfi-119.html > > Sweet-expressions may also be an alternative to explore. However, I > think Wisp is a more elegant base; it can transform *any* wisp code into > s-exp code. Not discussed in my blogpost about Wisp is that it also > supports infix via {3 + 4}. So ok, now we have that. And we can still > group: > > {3 + {8 + 4}} > > So that's points b) and c), but we don't have a) yet. Could we add it? > > I think we can extend wisp with one thing and get everything we want: if > you have func(arg1 arg2 arg3) where the parenthesis comes *immediately* > after the symbol, that is rewritten to (func arg1 arg2 arg3). I will > call this version ~Wisp. > > With all this, observe the following code rewritten from Scheme to ~Wisp: > > (define (rgb-maker mk) > (lambda (sz) > (vc-append (colorize (mk sz) "red") > (colorize (mk sz) "green") > (colorize (mk sz) "blue")))) > > define rgb-maker(mk) > lambda(sz) > vc-append(colorize(mk(sz) "red") > colorize(mk(sz) "green") > colorize(mk(sz) "blue")) > > Here is another chunk of code, taken from HTdP2: > > (and (or (= (string-length "hello world") > (string->number "11")) > (string=? "hello world" "good morning")) > (>= (+ (string-length "hello world") 60) 80)) > > To: > > and(or({string-length("hello world") = string->number("11")} > string=?("hello world" "good morning")) > {{(string-length "hello world") + 60} >= 80}) > > And in fact the latter can transform itself *directly* into the former. > And the former technically is also still valid Wisp: you can embed > s-expressions into it and they still work. > > I think this satisfies the requirements that Matthew laid out. > > There's another major advantage of this. We can now write languages > that work either like: > > #lang s-exp "mylang.rkt" > > or: > > #lang wisp "mylang.rkt" > > The main thing that Wisp is missing right now is editor tooling so that > doing indentation is convenient. But that's more than feasible to add, > imo. > > I think this is the best way to move forward without creating > significant divisions, throwing out valuable things we have, or making > future Racket Week courses all that much harder. What do people think? > > - Chris > -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/2772b17c-bf08-4e21-8fb4-e7067b5d1877%40googlegroups.com.