Hacker Newsnew | past | comments | ask | show | jobs | submit | samdphillips's commentslogin

> nice struct syntax

I am curious how you would change the struct syntax?


I don't have the creds to give a definitive answer, but I like C structs, JS dicts, Java object access, Haskell lenses, etc -- any kind of dot syntax.

Default Racket: (potato-skin-color apotato)

JS: apotato.skinColor

The extra potato upsets me. Some libraries exist to address this but I believe they all have caveats.

With copying or mutation, it's even worse:

Racket copy: (struct-copy potato apotato [skin-color 'brown])

Racket mutate: (set-potato-skin-color! apotato 'brown)

JS copy: { ...apotato, skinColor: 'brown' }

JS mutate: apotato.skinColor = 'brown'

None of this really ruins the language for me, considering pros vs cons as a whole, but sometimes I'm slowed down in that by the time I finish mentally spelling out and typing the struct accessing I half forget the context I was in, and in general I'm sensitive to "eye bleed". Sometimes Racket looks like:

(define define match-define define define-values define begin cond define define)

when the real meat of the algorithm is more like:

cond

...and where Haskell's "where"s, "|"s, and "="s shine.

I'm sure I've over-answered your question but it's the holidays and I'm bored :)

edit: Since Racket uses dot already, it would probably have to be a different character, or the other way around.


> - Is there a LISP dialect that doesn't suffer from this problem?

I am not sure what problem you are referring to. Racket has been actively developed since the mid-90s.


No, it is dynamically typed. The annotations work like run time contracts.


The easiest way would be to rename the imported names

  #lang rhombus
  
  import rhombus:
    only: fun ...
    rename fun as fn
    rename ... as …
    open

  fn all_same([str0, str, …]):
    all(str0 == str, …)


Python with extensible syntax and not afraid of functional programming.



You're critique is valid. `length` `vector-length` and `string-length` are from the very monomorphic old Scheme libraries.

The Racket module system does provide ways to use the names you want without having to change the core language. The `collections` package (https://pkgs.racket-lang.org/package/collections) also smooths over some of these issues.


Thanks for the tip! I'll look over the collections package for sure. It looks like some of the things of interest to me are there already.

I knew there were historical reasons behind some of these things (just like the old complaints about car and cdr not being called first and rest). Sometimes it feels like this hewing to history comes with some baggage that makes adoption a little more challenging.

I find myself writing the following in some of my projects, for example:

    (define-syntax (hash-ref* stx)
      (syntax-case stx ()
        [(_ hsh k1)        
         #'(hash-ref hsh k1)]
        [(_ hsh k1 k2 ...) 
         #'(hash-ref (hash-ref* hsh k1) k2 ...)]))
So that I can do something like:

    > (define hsh '#hash((a . #hash((b . c)))))
    > (hash-ref* hsh 'a 'b)
    'c
I feel a little silly each time because it seems like the sort of thing that should just "be there," in the way you can do something like hsh['a']['b'] in Python. Of course there are ways to make it a bit more like Clojure--I think Greg Hendershott created a Clojure-like layer called rackjure--so that you can access using the variable name, etc. It would be nice to have something standardized to make the ergonomics nicer.


Note that Scheme made this choice in order to make it simpler for compilers to produce efficient code.


Matthew has been working on a prototype (https://github.com/racket/rhombus-brainstorming/pull/163) that works on the current snapshot version of Racket.

It is possible to use to write some basic things and most existing Racket libraries are usable with the prototype.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: