Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Why not [1 2 3] and {foo 3 bar 4}? Clojure gets it right. :)


Two of the best parts of clojure (over other lisps).


For Common Lisp to support converting [1 2 3] to a vector:

  ; [] to #()
  (defun bracket-reader (stream char)
    (declare (ignore char))
      `(vector ,@(read-delimited-list #\] stream t)))
  (set-macro-character #\[ #'bracket-reader)
  (set-syntax-from-char #\] #\))
And for your in-place hash:

  ; {} to hash
  (defun set-hash-values (hash pairs)
    (when pairs
      (setf (gethash (car pairs) hash) (cadr pairs))
      (set-hash-values hash (cddr pairs))))
  
  (defun in-place-hash (stream char)
    (declare (ignore char))
      `(let ((hash (make-hash-table)))
         (set-hash-values hash ',(read-delimited-list #\} stream t))
         hash))
  
  (set-macro-character #\{ #'in-place-hash)
  (set-syntax-from-char #\} #\))
I just sketched these together. I am a CL noob. No doubt there are more concise approaches.




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

Search: