Arc Forumnew | comments | leaders | submit | sjs's commentslogin
4 points by sjs 6556 days ago | link | parent | on: Parser combinators (first try)

I fixed a few bugs and have pushed this to the git anarki: http://git.nex-3.com/arc-wiki.git

There is now a maybe combinator (like ? in a regex) and n-times, which is like {N} or {N,M} in a regex.

e.g.

    ((maybe "x") "hi") => (t "" "hi")
    ((maybe "x") "xhi") => (t "x" "hi")
    ((n-times any-char 3) "ab") => (nil nil "ab")
    ((n-times any-char 3) "abc") => (t "abc" "")
    ((n-times any-char 3) "abcd") => (t "abc" "d")
    ((n-times any-char 3 6) "abc") => (t "abc" "")
    ((n-times any-char 3 6) "abcd") => (t "abcd" "")
    ((n-times any-char 3 6) "abcdefg") => (t "abcdef" "g")
I'm starting to work on a simple markdown grammar, but so far it's all on paper. The library is not ready for real use yet but it's getting there.

-----


The same way that Seaside users do: without worry and with great pleasure.

-----

3 points by sjs 6557 days ago | link | parent | on: Editing Arc in TextMate...?

> This is the sort of thing that I'd rather just steal from someone else :-)

Me too. ;-)

I've been doing Arc stuff on my Linux box so far, which means mostly Emacs and quick edits in vi. Emacs has great support for parenthesized languages.

In TextMate I'm currently using the lisp bundle, but if I do anything significant on my MacBook I'm probably just going to do it in Emacs. Without Emacs I find lisp somewhat painful to write. For example, in TextMate I cannot choose how many sexps to wrap with then next paren. Say I have this code that I need to wrap with an if:

  (do (some code here))
In TextMate I must place the closing paren manually. Not a big deal in this case, but with more complicated code it can be tedious. Inserting the closing paren automatically in this case is a hassle, not a boon. You get:

  (<cursor>)(do (some code here))
And then you must adjust it manually.

In Emacs (with paredit-mode) I can hit Alt-1 ( and instead of getting "()" inserted, the closing paren wraps the following sexp. Alt-2 ( does the same but wraps the next 2 sexps. So you get:

  (<cursor>(do (some code here)))
And you just keep typing your code.

My advice is to just use Emacs and forget TextMate (for now, for Arc). I like TextMate for non-lisps so don't take this the wrong way. Right tool for the job and all that.

Sorry for the non-answer to your request. Just had to get my 2 cents in I guess.

-----

2 points by projectileboy 6557 days ago | link

No, no... This is helpful; thanks. I don't have any particular love for TextMate - it just seemed the quickest way to point B. (Actually, as a long time Blub programmer, my favorite text editor is IntelliJ. Go ahead and laugh... it's nicer than you think.)

-----

2 points by brett 6557 days ago | link

You can use selection for that in TextMate. If type ( with a block of text selected it wraps that block with parens.

-----

3 points by sjs 6556 days ago | link

That sort of works but still requires manual selection. Regardless there are many more reasons to work in Emacs when using lisp so I'll stick with it. (e.g. inferior-lisp-mode, send files or defs to a running lisp as you edit them)

-----

3 points by tel 6556 days ago | link

Textmate's lack of inferior process panes pretty much cripples it for most rapid iteration, REPL-esque programming in my mind.

-----

1 point by sjs 6559 days ago | link | parent | on: (coerce "99" 'int 16) = 153 ?

154 is a better example to avoid confusion.

(coerce "9a" 'int 16) => 154

(coerce 154 'string 16) => "9a"

(coerce 154 'string) => "154"

-----

1 point by sjs 6559 days ago | link | parent | on: Unquoting

But ``,x is certainly not the same as `',x

Here's a macro for illustration:

     (mac a (x y)
      `(do (prn ',x)
           (prn `,y)))
Compared with:

    (mac b (x y)
      `(do (prn ',x)
           (prn `,,y)))

    arc> (a 1 2)
    1
    Error: "reference to undefined identifier: _y"
    arc> (b 1 2)
    1
    2
    2

-----

1 point by sjs 6559 days ago | link | parent | on: REPL variables

So I guess that and thatexpr are obsoleted by this patch, no?

-----

3 points by parenthesis 6559 days ago | link

that and ^ do the same thing (but there's also ^^, ^^^).

thatexpr is like CL + .

But (%) is like (eval thatexpr), except % is a macro that gives you what the last thing entered expanded into. And so, since % is a macro, it itself is expanded away. Hence

  arc> 2
  2
  arc> (* ^ 2)
  4
  arc> (%) ; equivalent to entering (* ^ 2) again
  8
  arc> (%) ; and again
  16
  arc> (%) ; and again
  32
Whereas

  arc> 2
  2
  arc> (* ^ 2)
  4
  arc> (eval thatexpr) ; i.e. (eval (* ^ 2))
  8
  arc> (eval thatexpr) ; i.e. (eval (eval thatexpr)) i.e. (eval (eval (eval thatexpr))) etc.
  [infinite loop]

-----

1 point by sjs 6559 days ago | link | parent | on: REPL variables

You should update the original post.

-----

2 points by parenthesis 6559 days ago | link

You're right, but being able to edit one's posts is time limited, and I was too late.

-----

1 point by sjs 6559 days ago | link | parent | on: REPL variables

I changed it to:

    (tostring (mac % () expandedexpr))

-----

1 point by parenthesis 6559 days ago | link

Why does that work?

-----

2 points by sjs 6559 days ago | link

tostring captures whatever is sent to stdout.

    (tostring (prn "hi"))
returns the string "hi\n" instead of actually printing it.

-----


If you click on your username to view your profile there is a comments link at the bottom of that page that has been sufficient for me to follow conversations. ymmv.

-----

2 points by lojic 6559 days ago | link

Isn't that just the same as the 'threads' link? New comments can show up way down the page, and I don't feel like scrolling through every comment searching for recent ones - it's inefficient.

In other words, if someone replies to an older comment of mine, I probably won't see it.

-----

1 point by sjs 6560 days ago | link | parent | on: Alphabetical List of Arc Functions

Cool, not just functions but macros too.

-----

More