Arc Forumnew | comments | leaders | submit | absz's commentslogin
4 points by absz 6402 days ago | link | parent | on: Printing squares

defcall is pretty simple to use. The syntax is the same as that of def, except instead of a function name, you provide the type of the object. The function receives both the objects and its "arguments". E.g.

  arc> (defcall sym (self n)
         (repeat n (prn self))
  #<procedure>
  arc> ('a 3)
  a
  a
  a
  nil

.

-----

7 points by absz 6402 days ago | link | parent | on: Printing squares

On Anarki, you can add the ssyntax:

  (add-ssyntax-top
    ".." (range L r))
Then you have

  arc> 1..10
  (1 2 3 4 5 6 7 8 9 10)
.

EDIT: Actually, it's slightly nicer to do

  (add-ssyntax-top
    ".." (range ...))
so that you can then specify the step size:

  arc> 1..10
  (1 2 3 4 5 6 7 8 9 10)
  arc> 1..10..2
  (1 3 5 7 9)

.

-----

1 point by almkglor 6401 days ago | link

As an aside, this appears to be popular, it might be possible to add this to the ssyntax extension.

As an aside, I suspect that much of the slowdown from the new ssyntax/ssexpand comes from scheme-side 'ac emitting a lot of 'ar-eval calls, but I'm not sure, since I haven't studied 'ac output much yet.

-----

1 point by almkglor 6402 days ago | link

Where'd you implement 'add-ssyntax-top ? I can't seem to find it anywhere in Anarki.

-----

1 point by absz 6402 days ago | link

Whoops, forgot about that. It's just a thin wrapper around a-ssyntax-top:

  (mac add-ssyntax-top body
    `(a-ssyntax-top ',(pair body [list (string _1) _2])))
. It's just quoting and pairing things. It'd be nice to have a-ssyntax-bottom, too...

-----

1 point by almkglor 6401 days ago | link

I suggest you push this onto Anarki (and possibly implement a-ssyntax-bottom). ^^

-----

1 point by absz 6401 days ago | link

I will do so soon, and hopefully when I get a chance to study ssyntax.arc a little more, I will add a-ssyntax-bottom.

What might be nice would be to have numerical precedence levels (reals, not integers), so that you could add an operator later with the right precedence without redefining everything.

-----

1 point by sacado 6402 days ago | link

Oh, great, I forgot this one...

-----

1 point by absz 6402 days ago | link

I'm not sure what you mean by this: forgot that this functionality existed?

-----

1 point by sacado 6402 days ago | link

yep, that's it. I never used the ssyntax-definer, so I forgot it was existing. Sorry, but it's a little late here, so I can hardly even understand myself :)

-----

3 points by absz 6402 days ago | link | parent | on: Dual syntax for Arc

See also http://arclanguage.org/item?id=3477 for an infix macro, which should do most of what you want.

-----

3 points by absz 6403 days ago | link | parent | on: Nondeterminism

I think this doesn't quite work:

  arc> (amb 1 2)
  1
  arc> (amb (fail))
  2
  arc> (amb (fail))
  Error: "no more choices left"
My understanding is that when one leaves an amb, one can't use fail to return to it. Or am I supposed to be able to do this?

-----

2 points by rincewind 6403 days ago | link

I think this is supposed to work.

From "Teach yourself Scheme in Fixnum Days":

In particular, amb is required to return a value if at least one its subexpressions converges, ie, doesn't fail. Thus,

   (amb 1 (amb))

 and
   
   (amb (amb) 1)

 both return 1.
http://www.ccs.neu.edu/home/dorai/t-y-scheme/t-y-scheme-Z-H-...

-----

1 point by absz 6402 days ago | link

That doesn't actually address my concern, but this (from the same page) does:

  (if (amb #f #t)
    1
    (amb))
This has to force the first amb to return #t, or the whole expression would fail. I still find it somewhat odd, though, that I can (fail) on the next line, but I suppose there's not a better way to handle it; after all, that's probably just because the interpreter is sequential.

-----

6 points by absz 6403 days ago | link | parent | on: type dispatching

This exists on the Anarki, in the form of defcall: http://arclanguage.org/item?id=3743 . Yes, it's quite helpful :)

-----

2 points by bOR_ 6402 days ago | link

tempting reason to switch from arc2 to anarki :).If I understand right, I could make arc understand that if I have a list of lists, (mylist 3 2) wants the second position from the third list.

Nice, is this a something that you can influence locally, within a function, or is it a do-once-per-program thing of arc?

I'll keep it in mind when I'm extending and abstracting my first arc prog at http://bagofsouls.com/images/arc-life.arc :).

-----

2 points by almkglor 6402 days ago | link

Yes, this is possible, although you should note that 'defcall is global (do-once-per-program)

-----

1 point by bOR_ 6402 days ago | link

Is it possible to have it in a local way? (per function / module)

-----

1 point by almkglor 6401 days ago | link

No, or rather not yet.

It might be possible to do so by using some sort of dynamic global (a la kennytilton's implementation some time back, but using 'thread-local objects to handle it).

-----

3 points by conanite 6403 days ago | link

Aha, that was before my time. And there I was thinking I was being original. Thanks for the link.

-----

6 points by absz 6404 days ago | link | parent | on: Multiple Return Values?

You can also use nil or t as your "ignored variable", instead of _; they won't even be rebound. E.g.

  (let (a nil nil d) (range 1 4)
    (list a d))
produces the list (1 4).

-----

2 points by absz 6404 days ago | link | parent | on: Multiple Return Values?

No, it does not. Why do you want it? Perhaps there's a better (or at least more Arcish) way to accomplish it. Returning a list, for instance. To quote arc.arc:

  ; The problem with returning a list instead of multiple values is that
  ; you can't act as if the fn didn't return multiple vals in cases where
  ; you only want the first.  Not a big problem.
Also, a formatting tip: to get your text to appear as code, surround it by blank lines and indent it by two spaces.

-----

3 points by absz 6404 days ago | link | parent | on: Programming in a vacuum

This is a good point. There is a C interface, and C has innumerable libraries, but working with C can be… icky.

-----

1 point by absz 6406 days ago | link | parent | on: sorting table keys

The best way to do this is

  (sort (fn (a b)
          (< (tostring:write a)
             (tostring:write b)))
        (keys the-table))
; write will print the list, in that format, to stdout, and tostring captures stdout and puts it in a string, which it returns.

-----

1 point by bOR_ 6406 days ago | link

works like a charm. thanks!

-----

2 points by absz 6406 days ago | link | parent | on: Programming in a vacuum

Hear hear! Let there be libraries! The school year's almost over, and I'll contribute more then. And I second the idea of a list of necessary libraries that stefano proposed.

Also, has anyone else found themselves accumulating a file of utility functions? I have one with a little fewer than 30 functions which I find generally useful. There's probably some duplication of standard stuff, but there are also things that aren't. If other people have these, we might put the common functions on Anarki.

-----

2 points by almkglor 6406 days ago | link

I suggest that such simple routines be pushed onto Anarki then.

As an aside: it would probably be a good idea to start adding docstrings to everything in Anarki; this would help catch duplication of effort.

-----

3 points by stefano 6405 days ago | link

What about automatically collecting every function/documentation pair and putting everything on the Anarki wiki?

-----

1 point by almkglor 6404 days ago | link

Err, I don't understand exactly what you mean, can you expand on this?

-----

1 point by stefano 6403 days ago | link

I mean scanning Arc files or, better, the help* table and gather information in text files formatted in a wiki-friendly format in order to easily put them on the Anarki wiki.

Edit: have a look at the file lib/help-to-wiki in Anarki (just pushed it).

-----

1 point by almkglor 6402 days ago | link

Arki doesn't support tables yet.

Also, Arki supports <arc></arc> tags, which adds the help* table entries as the mouse hover strings on symbols.

-----

More