4 ms·
Well, Clojure doesn't have programmable reader macros either way. As long as you're not dead set on specific characters you could do: (defun extract-from-o
by axelrosen 8y ago
Well, Clojure doesn't have programmable reader macros either way.
As long as you're not dead set on specific characters you could do:
(defun extract-from-objc (obj)
(objc-typecase
obj
(%@NSDate [[[[%@NSISO8601DateFormatter @(alloc)]
@(init)]
@(stringFromDate:.) :pointer obj]
@(UTF8String)]s)
(%@NSString [obj @(UTF8String)]s)
(%@NSNumber (parse-number:parse-number
(objc-runtime:.:extract-nsstring
[obj @(stringValue)])))
(%@NSArray (map-nsarray #'extract-from-objc obj))
(%@NSDictionary (fw.lu:alist-string-hash-table
(pairlis (map-nsarray #'extract-from-objc [obj @(allKeys)])
(map-nsarray #'extract-from-objc [obj @(allValues)]))))
(t (or (funcall-some (cdr (objc-pick-by-type obj *objc-extractors*))
obj)
obj))))
The reason I say they're good for DSLs is exactly for re-purposing to have a special meaning.
Yes, nowhere close to being as powerful as reader macros.
But the nice part is everyone can and knows how to work with these primitives.
I do wish we had reader macros like CL, but I'd still totally want the built-in [] and {}.
- fiddlerwoaroof 8y agoI really like how most of the non-sexp syntax is optional in CL. Anyways, I'm also a bit ambivalent about the merits of [] vs. #(): I like how the latter syntax is more "standard", since the # dispatching macro character is used for a bunch of things. E.g. multidimensional arrays #2a() #3a() complex numbers #c(1 2) character literals #\space, pathnames #p"/foo/bar" etc.: it adds to the uniformity of the syntax, ime.
- fiddlerwoaroof 8y agoAnyways, I guess I like CL's approach where #[] #{} [] and {} are all specified as reserved to the user and then, using named-readtables, you can pick an appropriate implementation as you see fit.