Arc Forumnew | comments | leaders | submitlogin
Lisp Beginner
3 points by Styx 3324 days ago | 19 comments
Hi all, I'm Styx.

I was recently recommended the book, "The Little Schemer" which, through a little digging, has led me to look into learning Arc as my first Lisp.

I've hit a snag, however. TLS assumes that you're running a version of scheme, which I suppose Arc is in a way. Would you consider the two languages close enough that I might complete a book on scheme in Arc?

If so, my next problem is that TLS asks that I define a function "atom?" Which looks like this:

  (define atom?
     (lambda (x)
        (and (not (pair? x)) (not (null? x)))))
Obviously I would switch out "define" with "def" but what about the rest?

Any assistance is much appreciated. :)

EDIT: For clarity, the book requires that the function "atom?" operate in such a way that:

  (atom? (quote ()))
return false (or nil, heh.)

EDIT:EDIT: I also read in one of your recent threads that you guys might be starting a slack channel? If so, I'd love to pester you guys with my noob questions. :P



3 points by kinnard 3324 days ago | link

This might not be really helpful because the arc "atom" isn't quite the same as the lisp "atom"[1][2]

arc> (src atom)

(from "arc.arc")

(def atom (x)

  (in type.x 'int 'num 'sym 'char 'string))
==================================================

(define (ar-type x)

  (cond ((ar-tagged? x)     (vector-ref x 1))

        ((pair? x)          'cons)

        ((symbol? x)        'sym)

        ((null? x)          'sym)

        ((procedure? x)     'fn)

        ((char? x)          'char)

        ((string? x)        'string)

        ((exint? x)         'int)

        ((number? x)        'num)     ; unsure about this

        ((vector? x)        'vector)

        ((hash-table? x)    'table)

        ((output-port? x)   'output)

        ((input-port? x)    'input)

        ((tcp-listener? x)  'socket)

        ((exn? x)           'exception)

        ((thread? x)        'thread)

        ((thread-cell? x)   'thread-cell)

        ((keyword? x)       'keyword)

        (#t                 (err "Type: unknown type" x))))
(xdef type ar-type)

[1] https://github.com/arclanguage/anarki/issues/40#issuecomment...

[2] http://arclanguage.org/item?id=19492

-----

3 points by akkartik 3324 days ago | link

I think you can go pretty far treating Arc as a dialect of Scheme. Arc is basically like Scheme + Lisp-style macros. So until you start dealing with macros things should correspond pretty closely. The names change, as you already noticed, so () is nil and not is no[1]. A second point of difference is that Arc tends to have fewer parens, so for example this Scheme code:

  (let ((x 3) (y 4))
    ...)
turns into this in Arc:

  (with (x 3 y 4)
    ...)
Kinnard is right that the atom primitive is pretty much what you want. The exact transliteration of your definition would be:

  (def atom? (x)
    (and (no x) (no (alist x))))
Or, with more syntactic sugar:

  (def atom? (x)
    (and no.x (~alist x)))
[1] Hmm, somebody should write a "Arc for Scheme programmers" primer, just with a quick cheatsheet of common names and their equivalents. Any takers?

-----

3 points by rocketnia 3324 days ago | link

That version of `atom?` always returns nil, so I'll offer a correction.

Here's a very direct transliteration:

  (= atom?
    (fn (x)
      (and (no (acons x)) (no (no x)))))
The equivalents for `not` and `null?` in Arc are both `no`, because the empty list is the only falsy value. Scheme uses dedicated values for true and false, `t` and `#f`, but Arc uses the symbols `t` and `nil`, and `nil` doubles as the empty list.

Here's a version that uses the utilities Arc provides out of the box:

  (= atom? ~alist)

-----

3 points by Styx 3324 days ago | link

Also, from an outside perspective, I think your idea for a "Arc for Scheme" primer would be a great idea. The Little Schemer is widely recommended, so it could potentially result in more people finding their way into Arc.

-----

2 points by Styx 3324 days ago | link

Hey thanks Akkartik, I'll give it a go.

-----

2 points by kinnard 3324 days ago | link

Welcome!!! Best place to pester might be the github: https://github.com/arclanguage/anarki/issues.

Though I think a real stack exchange community is in order.

As to your question, I'm not qualified to answer, but it depends on your goals. What are your goals?

EDIT: Probably not though. Arc is intended to be "powerful"[1] not "educational" and Arc doesn't behave the way scheme does in(I believe) a lot of cases, e.g.: https://github.com/arclanguage/anarki/issues/48

[1] http://paulgraham.com/power.html

-----

2 points by akkartik 3324 days ago | link

I'm not sure how many people here follow the github account, so if you have questions just post them here. Don't worry about creating too many posts or comments, it's not like there's a lot of contention here :) Just do what works best for your learning, and we'll let you know if we want you to scale back.

If you see something broken or have suggestions to improve the documentation, post them on Github.

-----

2 points by Styx 3324 days ago | link

Yeah I figured that would be the deal getting into it, but I'm still willing to learn it. I think the whole philosophy is really neat.

I think what I'm going to try to do is continue to play around with Arc, while also learning on something a bit more established. Maybe Scheme or Clojure.

Thanks for the advice.

-----

3 points by kinnard 3324 days ago | link

Is there something you have in mind to build?

-----

3 points by Styx 3324 days ago | link

Well, I was thinking about building a chess engine in it at some point. But then, I intended to read a few books between now and then.

-----

3 points by kinnard 3324 days ago | link

That would be cool! "Chess engine" means no graphics, right?

-----

2 points by Styx 3324 days ago | link

Right. I created one in Ruby not too long ago. Then I decided I wanted to see it in the browser, so I used something called Opal to convert my Ruby code to JS. Then I built up the necessary html/css.

It's over at https://rawgit.com/Styx-/personal_website/master/index.html under projects if you want to see it.

-----

1 point by Styx 3324 days ago | link

Also, how much effort would it take to do something similar in Arc?

-----

1 point by kinnard 3324 days ago | link

You know . . . I have no idea . . :)

-----

2 points by kinnard 3324 days ago | link

What attracted you to LISP? And to Arc? If you don't mind my asking.

-----

2 points by Styx 3324 days ago | link

Mostly pg's essays. I'm actually fairly new to programming in general, though I have a ton of interest.

I'm coming from a Ruby background and I was just admitted to a coding bootcamp, for reference.

-----

2 points by kinnard 3324 days ago | link

I see. Yeah his essays are very seductive. I got pulled in.

Have you read the Roots of Lisp: http://lib.store.yahoo.net/lib/paulgraham/jmc.ps

-----

1 point by Styx 3324 days ago | link

Ah, well, I skimmed it yesterday. Which I guess skimming is the last thing to do when it comes to a document of that sort ^.^

Essentially, I want to learn Lisp because the colloquial "they" recommend it to gain a better understanding of programming in general.

I want to learn Arc because it seems to take the lisp philosophy to heart the most out of the lisps.

And generally, I'm the type of person that can withstand some amount of "jumping into the deep end." Although, I may be in a bit too deep this time. Heh.

I'll probably continue to lurk around here until I've got a bit more experience under my belt, and thoughts to contribute.

-----

2 points by kinnard 3324 days ago | link

It's definitely worth the read. It's the "Foundation" and nothing can beat knowing the axioms cold. That article was my red pill.

Arc isn't exactly living up to the vision: [1] https://github.com/arclanguage/anarki/issues/40#issuecomment... [2] http://arclanguage.org/item?id=19492

And the vision is questionable to begin with: http://arclanguage.org/item?id=19554

-----