
Struquine: A Useful Lisp Trick - soundsop
http://dorophone.blogspot.com/2008/08/struquine-useful-lisp-trick.html
======
swernli
Here is an arc version of the struquine macro:

    
    
      (mac strq (name . slots) 
         (withs (bname 
                 (coerce (string name "#") 'sym) 
                 creator `((def ,(coerce (string name "?") 'sym) (thing) (is (car thing) ',bname))
                           (def ,bname ,slots (cons ',bname (list ,@slots))))
                 accessors nil)
                (on arg slots
                    (= accessors (cons `(def ,(coerce (string name "-" arg) 'sym) (thing) (thing ,(+ index 1))) accessors)))
                (cons 'do (join accessors creator))))
    

I had to use "#" instead of "!" since that is used for special function access
in arc, but the effect of this code is pretty much what was written about in
the blog post. It creates a constructor for the struquine with name#,
accessors for each arg of the form name-arg, and "type" checker of the form
name?. For example:

    
    
      arc> (strq point x y)
      #<procedure: point#>
      arc> (= mypoint (point# 1 2))
      (point# 1 2)
      arc> (point? mypoint)
      t
      arc> (point-x mypoint)
      1
      arc> (point-y mypoint)
      2

------
yters
As I use other languages more and more, I begin to realize just how powerful
lisp's simple "everything is a list" paradigm is.

For example, one homework was to create an object oriented forum. The thing
was so complex because I was supposed to differentiate between forum, topic,
thread, and post. However, if I made a post a cons cell, then it all collapsed
into a branching list where everything is a post, which also gave me easy
branching threads.

