Arc Forumnew | comments | leaders | submit | tokipin's commentslogin

note aand works similarly, with the exception that it shorts on nil:

http://arcfn.com/doc/anaphoric.html#aand

-----

1 point by icemaze 6155 days ago | link

Wow, that's true! I don't use aand much so I didn't notice. Shorting on nil can definitely be a problem because sometimes you want to do something different; it's not very readable since "aand" suggests a boolean result; finally, my macro could be modified in different ways that diverge from the usual aand semantics (like having a special form to break from the pipeline).

Thanks for the comment.

-----

3 points by tokipin 6155 days ago | link | parent | on: Objects in Arc

well, we can closure the methods with the constructor function so they aren't duplicated, at the expense of explicitly requiring the object to be passed to them, or some kind of dispatch mechanism. we can also implement simple inheritance:

  (def inherits (obj1 obj2)
       (fn (key)
           (or (obj1 key) (obj2 key))))
with (apply or ...) we could have a long inheritance chain, but here i have just two objects so the pattern is clear. we can then define objects like so:

  (let _proto (obj
                full (fn (self) (string self!first " " self!last))
                until (fn (self year) (- year self!age)))
  
    (def person (first last age)
           (inherits (obj
                       _proto _proto
                       first first
                       last last
                       age age)
  
                     _proto))
  
  )

  arc> (= p (person "joe" "momma" 18))
  #<procedure>
  arc> (p!full p)
  "joe momma"
  arc> (p!until p 22)
  4
  
  arc> (= q (person "axe" "murderer" 10))
  #<procedure>
  arc> (q!full q)
  "axe murderer"
  arc> (q!until q 22)
  12
because the inheritance is dynamically dispatched or whatitbe, we can alter the methods with the intended effects:

  arc> (q!backwards q)
  Error: "Function call on inappropriate object nil (#<procedure>)"
  arc> (= ((q '_proto) 'backwards) (fn (self) (string self!last " " self!first)))
  #<procedure:gs2439>
  arc> (q!backwards q)
  "murderer axe"
  arc> (p!backwards p)
  "momma joe"

  arc> (= ((q '_proto) 'until) (fn (self age) "a long time"))
  #<procedure:gs2451>
  arc> (q!until q 22)
  "a long time"
  arc> (p!until p 18)
  "a long time"
note the 'inherits' function is agnostic. we can inherit from arbitrary objects and functions or what have you, just that in this case it was used to inherit from a hidden prototype

anarki supposedly has user definable syntatic sugaries, so the (q!blah q) pattern could be sugarized

-----

2 points by almkglor 6155 days ago | link

http://arclanguage.org/item?id=7365

-----


this reminds me of what this other clever guy proposed before: http://arclanguage.org/item?id=5586

-----

3 points by tokipin 6157 days ago | link | parent | on: Objects in Arc

i'd do it something like:

  (def person (first last age)
       (let self nil
         (= self (obj
           first first
           last last
           age age
           full (fn () (string self!first " " self!last))
           until (fn (year) (- year self!age))))))

-----

1 point by EliAndrewC 6156 days ago | link

Wow, that's much better! I didn't think that would work, since I thought that Arc's lexical scope bound variables in inner functions to the current value of those variables. Apparently I was wrong; thanks for the tip.

-----

1 point by tokipin 6173 days ago | link | parent | on: ([+ _ 10]:[* _ 20] 10) = error...

it works with macros as well, which makes for a convenient "modifier" syntax

example: http://arclanguage.com/item?id=4436

-----

1 point by almkglor 6173 days ago | link

The "ultimate" modifier being p-m:

http://arclanguage.org/item?id=2556

-----

3 points by tokipin 6177 days ago | link | parent | on: Lisp-style function definitions

remember also that Arc autodestructurizes arguments based on the parameter list (example: http://arclanguage.org/item?id=6125.) scheme-style def would would conceptually interfere with that

though maybe scheme autodestructurizes like that also? i don't know

-----

1 point by conanite 6176 days ago | link

arc lets us write

  (def foo args ...

  (def foo (x y . rest) ...
so that args is the list of all arguments, and rest is the list of all arguments after the first two. I suppose the equivalent scheme-ish way would be

  (def (foo . args) ...

  (def (foo x y . args) ...
I like the fact that arc has no special &rest keyword, that rest args just fall out of the way lists are constructed.

I haven't used scheme so I'm not qualified to comment (but obviously that's not stopping me), but to this n00b it makes sense that the parameter list is distinct from the function name. And as you mention it makes named functions look more similar to anonymous functions. So I have less thinking to do when I'm looking at a parameter list.

-----

8 points by tokipin 6200 days ago | link | parent | on: String to code

read: http://arcfn.com/doc/io.html#read

  (eval (read "(+ 5 5)"))

  (eval:read "(+ 5 5)") ; <- maybe nicer
there might be a better way. eval applies everything in the global scope, which is ok in some instances and incovenient in others

-----

3 points by tokipin 6205 days ago | link | parent | on: Kenny Tilton, ranting

come to think of it, i really never hear about software written in lisp, and that is kind of bad. it could be the real reason lisp isn't popular

-----

5 points by kennytilton 6205 days ago | link

Lisp is not popular because it was not at the right place at the right time. Other languages were, but that is all they were. Lisp meanshile is as good (and superior) as it ever was. And it is catching on, part of why I ranted that it is time to stop wringing our hands over Lisp's popularity and start programming with it. Or Arc. :)

-----

2 points by almkglor 6205 days ago | link

> Lisp meanshile is as good (and superior) as it ever was

Really, kenny, lisping while you type? You must be drinking even more than usual... ^^ \/

-----

1 point by parenthesis 6205 days ago | link

Well, here are some standard examples:

ITA, InspireData, PWGL, Viaweb, news.yc, reddit (initially), ...

-----


has anyone made a modification to make it more like a standard forum (as opposed to a news site) ?

-----

4 points by tung 6208 days ago | link

The system uses some sort of equation based on the submission time and points of each topic to determine the topic ordering. Changing that equation to use the last response time of each topic would do it.

-----


i don't know what 'define' is. is it a local assignment?

  (def fun ()               (def fun ()
    (local var 0)    ===      (let var 0
    (w/e var))                  (w/e var))

-----

1 point by drcode 6209 days ago | link

The original pg article referenced was about having local variables without a let. This article, as a whole, is a bit confused, so it's hard to know what he's trying to say. Bottom line, I don't think he got the gist of the pg essay he references...

-----

3 points by cooldude127 6207 days ago | link

i actually don't really want local variables without a let. i prefer the explicit scoping of a let binding. i often wish i had it in other languages.

-----

More