Arc Forumnew | comments | leaders | submitlogin
2 points by c-a-smallwood 4156 days ago | link | parent | on: Two useful language extension ideas

In my opinion defextend is fine the way it is, it has its similarities to CLOS's defmethod, which I would avidly abuse in my earlier lisp days.

The positive thing about adding a tagged predicate dispatch table, if implemented into "isa", would be the illusion of any object being a particular "type", provided it satisfies the predicate. In reality, the true type of the object would be cons or sym or whatever its value is.

One simple idea: The int/num difference could theoretically be moved into arc codespace via deftag. Primarily leave the number type "num" internally, but deduce if a number is an "int" via the tags table.

Example:

  (deftag int
    (and (isa _ 'num)
         (is _ (round _))))
  
  (isa 1.5 'int) => nil
  (isa 1 'int) => t
One cool thing you could do is define tags for something like an object descriptor, or a class. Store whatever you need in cons cells, along with maybe a symbol at the head named "class:" or something, with "slots:" or "methods:" in that class. This could easily be checked if a particular cons resembles a "[class]" structured cons via a predicate, right? So deftag a predicate for "class". Then check if your object is a class-structed cons via "isa".

Example:

  (deftag class
    (and (alist _)
         (is len._ 3)
         (is car._ 'class:)
         (alist cadr._)
         (>= (len cadr._) 1)
         (is (car cadr._) 'slots:)
         (alist (car:cddr _))
         (>= (len:car:cddr _) 1)
         (is (caar:cddr _) 'methods)))

  (= foo '(class:
            (slots: bar)
            (methods: baz)))

  (isa foo 'class) => t
  (isa foo 'cons) => t
  (type foo) => cons
  (alist foo) => t
2 points by akkartik 4156 days ago | link | parent | on: Two useful language extension ideas

Ah, I see. I understand now why Pauan brought up predicate dispatch.

Incidentally, anarki does predicate dispatch through defextend:

  (defextend some (test seq) (isa seq 'string)
    (let f testify.test
      (recstring f:seq seq)))
(https://github.com/arclanguage/anarki/blob/97b3464256/arc.ar...)

Would this be easier to express using the tags table?

2 points by c-a-smallwood 4156 days ago | link | parent | on: Two useful language extension ideas

Try to think of it as an add-on, not a replacement. If you were to rewrite "isa" to first check if the type you're checking for is the builtin expression type or the tag, and if it's not, lookup the symbol in the "tags" table. If the key is not bound, it returns nil. If the key is bound, apply the predicate bound to the key to the value supplied to "isa".

Example:

(deftag posnum (and (isa _ 'num) (> _ 0)))

(isa 1 'posnum) => t

(isa 0 'posnum) => nil

(isa 1 'blah) => nil

3 points by Pauan 4157 days ago | link | parent | on: Two useful language extension ideas

You can indent a code block by 2 spaces to format it as code.

---

Your idea of types is similar to Predicate Dispatch[1]. I believe it's also similar to Racket's contracts[2].

This is an extremely powerful type system in the sense that you can express literally anything with it. However, I believe that a more restrictive type system can actually be better, because it provides more guarantees (especially at compile-time).

---

I don't think it's possible to pattern match on a function's arguments, body, and closure, simply because Racket doesn't expose those things.

I do approve of pattern matching, though.

---

* [1]: http://en.wikipedia.org/wiki/Predicate_dispatch

* [2]: http://docs.racket-lang.org/guide/contracts.html?q=contract

2 points by akkartik 4157 days ago | link | parent | on: Two useful language extension ideas

Anarki does have pattern matching: https://github.com/arclanguage/anarki/blob/master/lib/defpat... (by user almkglor). It hasn't been used in years to my knowledge, though. If you try it out I'd love to hear experiences and will try to help fix any bugs you find. I like the idea in theory and tried to use it in my wart language (https://github.com/akkartik/wart/blob/master/061patmatch.tes...) but didn't make much headway so far.

(More info: http://arclanguage.org/item?id=2556)

I'm having more trouble understanding deftype. (I'd never come across it so far in my common lisp experience.) I couldn't tell what the benefit would be of your ((tags 'posnum) 0) examples over just a simple predicate. Won't it only be useful if arc actually got optional typing like common lisp?

(Also, I assume you're familiar with arc's approach to types using annotate and rep?)

2 points by akkartik 4175 days ago | link | parent | on: About a example in arc-handbook!!!

This forum isn't for the Altarica. It's for an unrelated programming language called Arc. Sorry about the confusion.
1 point by Jetlee 4175 days ago | link | parent | on: About a example in arc-handbook!!!

I hope you can help me. Thank you.
1 point by Jetlee 4175 days ago | link | parent | on: About a example in arc-handbook!!!

I'm a student. Recently, I learning Altarica for analysis a model(system). But I don't kown how to do when I encounter some problems, like I mentioned above. Now, I try a case 'Design of a lift', when I analysis it's safety, it's report a error.
2 points by akkartik 4176 days ago | link | parent | on: About a example in arc-handbook!!!

The command set arc.shell.preprocessor.default.command "/usr/bin/cpp" isn't legal arc (the one this forum is about). From googling around, the handbook you're reading (http://altarica.labri.fr/docs/arc-handbook.pdf) seems to be about that link I mentioned above.

Anyway, tell us what you are trying to do, and I'll tell you which of these is better for you :)

1 point by Jetlee 4176 days ago | link | parent | on: About a example in arc-handbook!!!

what do you mean? I encounter a problem in using Arc.
1 point by Jetlee 4176 days ago | link | parent | on: About a example in arc-handbook!!!

what should I do?
1 point by akkartik 4176 days ago | link | parent | on: About a example in arc-handbook!!!

Unfortunately this site is entirely unrelated to http://altarica.labri.fr.
2 points by Pauan 4177 days ago | link | parent | on: Why is "do" a macro and not a function?

That's a good point. In Nulan, you can't redefine things (all variables are constant). I'm not so worried about performance right now. My main concern is simplicity, since implementing "do" as a macro introduces a lot of extra complexity (because Nulan compiles to JavaScript).

The first (and only) reason that comes to my mind is: efficiency. Calling a function that takes rest args means allocating a list at runtime; the usual expansion for "do" is a direct call to a lambda, which the Racket compiler seems able to handle with no runtime cost. Thus:

  arc> (def do-func args last.args)
  #<procedure: do-func>
  arc> (mac do-macro args `((fn () ,@args)))
  #(tagged mac #<procedure: do-macro>)
  arc> (time:repeat 1000000 (do-func 1 2 3))
  time: 270 cpu: 270 gc: 6 mem: -4392856
  nil
  arc> (time:repeat 1000000 (do-macro 1 2 3))
  time: 69 cpu: 70 gc: 0 mem: 928
  nil
  arc> (time:repeat 1000000 1 2 3)
  time: 67 cpu: 68 gc: 0 mem: 128
  nil
It is not too far-fetched an idea for a compiler to eliminate the runtime overhead of the calls to "do-func". Basically this would require assuming that "do-func" will not be redefined at runtime--which is permitted in Arc, so it would require the compiler to make optimistic assumptions and be prepared to invalidate the code when they are violated (i.e. if someone actually does redefine "do-func" at runtime). I've heard the best Javascript engines do this, but Racket does not.

In your use case, having a "do" that works at all is better than none, and I don't think there is any logical problem with doing so. (Strictly speaking, it makes it possible to "do" [!] more things, since you can't apply a macro.)

3 points by Pauan 4180 days ago | link | parent | on: Why is "do" a macro and not a function?

Well, no, because "do" returns the last argument, so it would be:

  (def do args (last args))
2 points by akkartik 4181 days ago | link | parent | on: Why is "do" a macro and not a function?

So you mean (def newdo args)? My mind is blown.
3 points by lojic 4188 days ago | link | parent | on: Interested in being an Arc tutor?

I've mainly just been learning the language. Working through some tutorials, reading books/articles, coding, etc. Did a few Project Euler problems, and now I'm working through SICP.

I burned a lot of time looking for my (not "the") perfect language, and finally settled on Racket for the dynamic language and OCaml for the statically typed language.

Now I'm trying see which problems are best suited to each of them.

Clojure has a lot of good things, but I've never been able to get past the dependency on the JVM, lack of tail calls, etc., but it's pretty darn concise.

The Racket community is incredibly strong IMO.

2 points by jsgrahamus 4188 days ago | link | parent | on: Interested in being an Arc tutor?

lojic - What did you end up using Racket for?
3 points by lojic 4189 days ago | link | parent | on: Interested in being an Arc tutor?

I think anyone who is interested in a lisp has been positively influenced by Paul Graham, I certainly have.

You said this in the HN thread:

"I'm sure Arc is the wrong choice if I want to be as effective as possible in 6 months. If Arc is only the best choice if I want to be as effective as possible in 5+ years someone save me ;)"

The specific language is only one aspect of effectiveness - others include available libraries, an active contributing community, etc. I don't think there's reliable evidence that Arc will change enough in 3 years to fulfill your "effective as possible" goal.

Paul's last submission to his own forum has been over 5 years ago! And his last comment has been over 4 years ago. It would seem that he's not actively involved any more.

I was very excited to hear about Arc over 7 years ago, and I had high hopes that Paul might be the person to create a successful lisp and rally a great community. This has not happened, and I think it would be foolish to think this will change much in the next three years.

In the end, I ended up choosing Racket as my lisp - it made my short list to evaluate in part because Paul chose it to implement Arc :)

I'm certainly not trying to "save [you]", but I see many similarities between your quest for the most effective language and my own and countless others :) The language is very important, and concision is important, but you really need to evaluate the entire ecosystem to make a good choice.


Yeah, that's a bug on my part in anarki. Thanks for the report!

Edit 10 minutes later: now fixed: https://github.com/arclanguage/anarki/commit/fcfbfcdb80. Thanks again.

2 points by jackcouch 4190 days ago | link | parent | on: Interested in being an Arc tutor?

Sounds great. My email is jack8couch@gmail.com. Send me your contact info. Really looking forward to it.
1 point by akkartik 4190 days ago | link | parent | on: Interested in being an Arc tutor?

Me too. How about we get together in person to discuss more details?
2 points by jackcouch 4190 days ago | link | parent | on: Interested in being an Arc tutor?

Actually I live in the SF area (eastbay) so if it is helpful to be in person I can do that too. I'm flexible.
2 points by jackcouch 4190 days ago | link | parent | on: Interested in being an Arc tutor?

Video (Google hangouts?) when needed, but most of the time (once I'm up and running especially) email will probably be fine.
3 points by akkartik 4190 days ago | link | parent | on: Interested in being an Arc tutor?

I think I might be interested. I've been working on teaching people programming a lot, but haven't really had a chance to teach my favorite language. Are you thinking in person or over video conference?
3 points by jsgrahamus 4190 days ago | link | parent | on: Interested in being an Arc tutor?

https://news.ycombinator.com/item?id=8906375
1 point by akkartik 4192 days ago | link | parent | on: Executing files in windows

Great! Keep asking us questions as you do more learning.
2 points by Benben 4192 days ago | link | parent | on: Executing files in windows

i got the syntax wrong, now it works. thanks
2 points by zck 4194 days ago | link | parent | on: Executing files in windows

This should work as long as foo.arc is in the same directory you're running Arc out of.

If your file is somewhere else, you'll have to specify the full path to it (warning: untested):

  arc> (load "C:\\Users\\Benben\\Documents\\foo.arc")
3 points by akkartik 4195 days ago | link | parent | on: Executing files in windows

I think that should be platform-independent:

  arc> (load "foo.arc")
Am I misunderstanding your question?

(Sorry about the delay in noticing your question.)

More