Arc Forumnew | comments | leaders | submitlogin
4 points by suzuki 3844 days ago | link | parent

My Semi-Arc 10.1 looks perfect;)

  $ java -jar semi_arc.jar 
  arc> (let ((o x 2)) nil x)
  arc> (let (a (o b 2)) '(1) b)
  arc> (let default 2 ((fn ((o x default)) x)))
  arc> (let default 2 (let ((o x default)) nil x))
  arc> (let default 2 (let (a (o b default)) '(1) b))
  arc> (let (x y) '(a b c) y)
  *** 2 args expected for #<fn:2::(#((a b c)))>: (a b c)
    0: (#<done> #<fn:2::(#((a b c)))> a b c)
  arc> (let (x y z nothing) '(a b c) nothing)
  *** 4 args expected for #<fn:4::(#((a b c)))>: (a b c)
    0: (#<done> #<fn:4::(#((a b c)))> a b c)

2 points by rocketnia 3843 days ago | link

I upvoted you 'cause Semi-Arc's doing what you want it to do (which is what really matters), but I'd like to mention that I actually kinda appreciate the way Arc accepts mismatched destructuring lengths.

I've seen other people's code use a (let (a b c) nil ...) idiom as a shortcut for (with (a nil b nil c nil) ...). As for me, I like being able to design multiple types so that they can be used in an ad-hoc polymorphic way like this:

    (def theta (point)
      (let (x y) rep.point
        (errsafe:atan y x)))
  #<procedure: theta>
    (let point (annotate 'point3d
                 '(-1 0 200))
Both these techniques could still be used in an Arc implementation with a stricter treatment of destructuring: The first could be done by defining a 'w/nil macro, and the second could be expressed as (let (x y . rest) rep.point ...). In your favor, the strict treatment makes it easier to write functions that do complain if the length is incorrect, encouraging fail-fast code. However, as far as portability is concerned, the "N args expected" errors are a quirk of Semi-Arc.

I'm going to try out Semi-Arc right now. ^_^ I'm sure I'll have some error reports for you in a moment. Hopefully not too many! :-p


1 point by akkartik 3843 days ago | link

Nice. Have you played around with multiple arc implementations in the process of making semi-arc? I'd love to read about your experience writing semi-arc, and the design decisions you made. (email in profile if you want to chat further)


4 points by suzuki 3843 days ago | link

No, I have not played the original Arc yet and had hardly known both implementations in Java until recently. My version 1 implementation was a little Lisp written in ISO Standard Pascal:

  Little Lambda Lisp in Standard Pascal
You find the notable(?) feature of Semi-Arc, macro expansion without free symbol capture, even in the version 2 of it:

  Little Lambda Lisp 2 in Standard Pascal
I had translated it to Ruby, Python, C# and Java. Recently I noticed that its design is near to the core of Arc. I made it up so that it may look Arc:-). The result is Semi-Arc.

As for argument destructuring, I implemented it in a simple, general and recursive (but not so efficient) way. Track the variable 'nestedArgs' in the method 'compile(Cell j, Cell env)' in the source:
Also, you can inspect the implementation interactively:

  arc> (def f ((a b)) (+ a b))
  arc> (inspect f)
  (#<fn> ((1)) (apply (#<fn> ((2) #<none>) (+ #0:0:a #0:1:b)) #0:0:$G453))