Arc Forumnew | comments | leaders | submit | twilightsentry's commentslogin
1 point by twilightsentry 4383 days ago | link | parent | on: Multiple cases in 'case branches

D'oh. Yeah; I have it defined, and I hadn't tried reloading arc before I posted it. _On_Lisp_ has a CL version; in Arc I do:

  (def mklist (xs)
    (check xs alist (list xs)))

-----

1 point by twilightsentry 4383 days ago | link | parent | on: Multiple cases in 'case branches

I've got a macro like that, which I call 'test. The problem with combining that and 'case is distinguishing functions and constants before the cases are eval'ed.

  (mac testlet (var expr . args)
    (letf ex (args)
           (if cdr.args
               `(if (,car.args ,var) ,cadr.args
                    ,(args cddr.args))
               car.xs)
      `(let ,var ,expr ,(ex args))))
Anyway, I'll probably just define 'casein as aw and rntz suggested.

-----

4 points by twilightsentry 4414 days ago | link | parent | on: Simple genome analysis with Arc

  > I'm sure there must be a better way to initialize the
  > count in Arc, but I couldn't figure one out.
Table lookups can take a default value as a third arg, so you could do something like:

  (def hist (seq)
    (w/table h
      (each n seq
        (++ (h n 0)))
      h))

-----

3 points by palsecam 4413 days ago | link

FTR, 'hist could be just:

  (def hist (seq)
    (w/table h
      (each n seq
        (++ (h n 0)))))
I just learned about 'w/table reading your post, and I checked, and it returns the created hash. This is quite smart, I often find myself doing things like:

  (let h (table)
    ...  ; do stuff with h
    h)  ; return it
Where it's actually possible to do:

  (w/table h
    ...)  ; implicit return of "h"
But yes, here, use 'counts.

-----

4 points by aw 4414 days ago | link

Also see "counts" in arc.arc:

  arc> (counts '(a b c a a a c))
  #hash((a . 4) (c . 2) (b . 1))

-----

3 points by kens 4414 days ago | link

Oh, yeah, I forgot that Arc 3 has default values for table. Someone should write some documentation on this :-)

Thanks for the suggestions; I've updated my blog post.

-----

2 points by twilightsentry 4426 days ago | link | parent | on: Rainbow: client-socket

In Anarki there's a similar function called 'socket-connect; we should probably decide between that and 'client-socket and use the same name for both.

-----

2 points by conanite 4425 days ago | link

"client-socket-connect" :))

I'm not attached to the name, and have no objections to switching to 'socket-connect. It's only unfortunate that arc's native "open-socket" doesn't proclaim its server nature, so I figured the word "client" would help disambiguate.

-----

1 point by thaddeus 4425 days ago | link

how about: socket-to-em

lol.

-----

4 points by twilightsentry 4501 days ago | link | parent | on: Show Arc: first program

  > (= doomsday* 1) ; how to represent infinity? 1 will do,
  > till Arc gets support.
Arc supports infinity as well as anything that uses ieee floating point. Mzscheme can directly read it with something like:

  (= doomsday* +inf.0)
Alternatively, you can divide by 0, if you're sure that the division will happen in float-mode -- division-by-zero is well-defined in ieee floating arithmetic.

  arc> (/ 1.0 0.0)
  +inf.0

-----


What about a macro something like:

  (mac =map (f . args)
    `(= ,@(mappend (fn ((v . xs))
                     `(,v (,f ,@xs)))
                   args)))

  (=map brackify
    (rbrackify "(" ")")
    (cbrackify "{" "}")
    (sbrackify "[" "]"))

-----

5 points by twilightsentry 4517 days ago | link | parent | on: Basic currying

My motivation for currying macros came from the recent "afn with" discussion. I had a w/afn macro which looked like a manually-curried function, so I figured it wouldn't hurt to add it to the curry fn:

  (mac w/afn args
    `(w/rfn self ,@args))
vs.

  (= w/afn (>_ w/rfn 'self))
Your [] syntax definitely looks useful, but I use (fn ((x y))) more than (fn (x y)).

-----

3 points by rntz 4517 days ago | link

Huh. I hadn't thought of anaphoric macros (like afn and afnwith), but it's true: they're good examples of macro currying.

-----

2 points by twilightsentry 4520 days ago | link | parent | on: Afn with

How about a variant for cases like:

(def foo (bar baz) (afnwith (bar bar baz baz) ...))

Maybe something like

(def foo (bar baz) (w/afn (bar baz) ...))

?

-----

2 points by absz 4519 days ago | link

I like this:

  (mac w/rfn (name withses . body)
    `(rfnwith ,name ,(mappend [list _ _] withses) ,@body))

  (mac w/afn (withses . body)
    `(w/rfn ,withses ,@body)
I have something like this for obj, actually, which I use for creating structure-like tables:

  (mac nobj args
    " Creates a table from the list of variables passed to it; each variable's
      name is keyed to its value.  E.g. if x = 10 and y = -10, then (nobj x y)
      results in #hash((y . -10) (x . 10)).
      See also [[obj]] [[table]] "
    `(obj ,@(mappend [list _ _] args)))

-----

2 points by conanite 4519 days ago | link

don't forget the name parameter to w/rfn in w/afn

  (mac w/afn (withses . body)
    `(w/rfn self ,withses ,@body)

-----

1 point by absz 4519 days ago | link

Whoops, you're right. My bad.

-----

2 points by twilightsentry 4553 days ago | link | parent | on: Compiler/translator using Arc?

Have you looked at _Essentials of Programming Languages_? It focuses on interpreters rather than compilers, but its a good place to start if you're not clear about how to lower some construct (eg, closures) that your syntax defines but which don't directly correspond to something in vbs.

On a side note, is there any particular reason you wouldn't want to use a lispey syntax? You get a lexer for free, and could implement whatever domain-specific constructs you like as macros.

-----