|
|
|
|
|
by axelrosen
2722 days 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 {}. |
|