Arc Forumnew | comments | leaders | submitlogin
1 point by akkartik 4608 days ago | link | parent

(Are you reading the tutorial at http://ycombinator.com/arc/tut.txt?)

It helps to put yourself in the shoes of arc and see the rules it follows in evaluating each statement.

  arc> (= 'x 5)
  Error: ...
= is special in that it doesn't evaluate its first argument. So just say:

  arc> (= x 5)
  5
---

  arc> x
  5
Arc here reads an expression that's a single symbol, so it evaluates it to lookup its value: 5.

---

  arc> 'x
  x
Arc here reads an expression that's short for (quote x). quote simply prevents its argument from being evaluated. So you get the symbol back: x.

---

  arc> (+ (car '(x)) 2)
  Error: ...
Arc here evaluates +. Plus is not special, so arc proceeds to evaluate all its arguments. (car '(x)) evaluates to x (just the symbol, not the value). 2 evaluates to just the number 2. Plus doesn't know how to deal with symbols so it throws an error.

---

  arc> (+ (eval (car '(x))) 2)
  7
This is like last time, except that the call to eval looks up the value of x like in the second example above. Now both arguments to Plus are numbers, and it can add them.

The key is that evaluation happens in very precise and predictable ways in lisp. If you use quote to suppress evaluation you must call eval if you later change your mind and do want to evaluate.

---

Pop quiz: type these into the repl:

  arc> (= x 'y)
  arc> (= y 2)
Now before you try each of the following, try to guess what it will return:

  arc> x
  arc> y
  arc> (eval x)
  arc> (eval y)
If it's easier we can go over more examples interactively over chat somewhere. Let me know if you want to try that; you'll see my email if you click on my username above.

Also, please just copy-paste the session from your terminal in future. A scanned image makes it harder for future readers to search for your question.



2 points by rocketnia 4608 days ago | link

"Also, please just copy-paste the session from your terminal in future."

To do this in a Windows terminal, right-click anywhere in the text and select "Mark". (You can also select "Mark" by clicking on the top-left icon and going to the "Edit" submenu.) Now you can draw a rectangle with your mouse, or with the arrow keys and shift.

Once you're satisfied with your rectangle, right-click in the window again or press enter. The contents of the rectangle are now in your clipboard, not including trailing whitespace.

You can cancel by doing something else, like pressing escape.

The rectangle interface might seem a little insane, but I'm half-looking-forward to the time when it comes in handy for copying tabular data or ASCII art. Or Epigram programs. :-p

-----

1 point by FredBrach 4608 days ago | link

>> Also, please just copy-paste the session from your terminal in future.

I see, I will.

>> If it's easier we can go over more examples interactively over chat somewhere. Let me know if you want to try that; you'll see my email if you click on my username above.

Cool, that's more fun for sure :)

>> ... (the other points) ...

Fortunately I got those things. Also seems like the prompt is doing (pr (eval MyPrg))

-----

2 points by akkartik 4608 days ago | link

> "seems like the prompt is doing (pr (eval MyPrg))"

Exactly! Lisp and similar languages are said to have a read-eval-print loop or REPL. The interpreter Reads an expression from the prompt, Eval's it, and then Prints the result.

-----

1 point by FredBrach 4608 days ago | link

arc> (= x 'y)

'y

arc> (= y 2)

2

arc> x

'y

arc> y

2

arc> (eval x)

y

arc> (eval y)

2

-----

1 point by akkartik 4607 days ago | link

Great. Now try them out :)

-----

2 points by FredBrach 4607 days ago | link

arc> (= x 'y)

y

-_-

and then

arc> (eval x)

2

So fun :)

-----