jathak / dart_scheme

Online Scheme interpreter, formerly for 61A
https://scheme.jenthakar.com
BSD 3-Clause "New" or "Revised" License
45 stars 5 forks source link

Add string->symbol #80

Open nixxon opened 6 years ago

nixxon commented 6 years ago

Although it's not that hard to add them on my own, (in a hacky roundabout way), I thing this 3 important functions should be included in default scheme library:

(define (macroexpand-1 exp)
  (apply (eval (car exp)) (cdr exp)))
(define (gensym . prefix)
  (if (null? prefix)
      (string->symbol (string-append "gsym_" (random-string)))
      (string->symbol (string-append (car prefix) "_" (random-string)))))
(define (string->symbol str)
  (deserialize
    (string-append "{\"type\":\"SchemeSymbol\", \"value\":\""
                   str
                   "\"}")))
(define (random-string)
  (js "Math.random().toString(36).substring(2, 15)"))
jathak commented 5 years ago

I'm going to re-target this issue to focus on string->symbol only, since it's a useful, lowish-level procedure that requires hacks to build yourself.

As for the others, they're not in R5RS, they're not useful in a 61A-context, and they're relatively simple to build with the existing built-ins, so I'd prefer to leave them out, at least for now.

Once #83 is done, I'd be fine with an optional library of additional macro utilities, but probably wouldn't have time to implement one myself.