Arc Forumnew | comments | leaders | submit | jsgrahamus's commentslogin
2 points by jsgrahamus 3 days ago | link | parent | on: Multiple Return Values

Why avoid = in lisp/arc?

reply

1 point by akkartik 3 days ago | link

As long as you use '=' it's easy to keep programming C or MUMPS in Lisp. Avoiding '=' forces you to give up old habits and become fluent with (writing as well as reading) deeply nested calls, 'let' and recursion. Those are some big reasons to use Lisp rather than imperative languages. So if you don't use them you're missing out.

reply

2 points by jsgrahamus 3 days ago | link

Makes sense. Thanks.

It really does force me to think a different way. Painful sometimes, too.

reply

2 points by jsgrahamus 3 days ago | link | parent | on: Multiple Return Values

So say you have some variables to capture the return from one function so you can feed it into another 1 or more functions:

  (with (latitude 0 longitude 0
     result (func1 street-number street city state))
     (= latitude (pop result))
     (= longitude (pop result))
     (make-map latitude longitude)
     (func2 latitude)
     (func3 longitude))
Is there a better way of capturing the results of one function?

reply

2 points by akkartik 3 days ago | link

  (let (latitude longitude)  (func1 street-number street city state)
     (make-map latitude longitude)
     (func2 latitude)
     (func3 longitude))

reply

2 points by jsgrahamus 3 days ago | link | parent | on: Multiple Return Values

Thanks. So, how do you get the 2 results from func1 into latitude and longitude?

reply

2 points by akkartik 3 days ago | link

My code snippet is doing that. The let is doing a sort of pattern matching and binding latitude to the first element of the result, and longitude to the second.

reply

2 points by zck 3 days ago | link

I'll explain a little further, because Arc's let is unusual. Unlike most Lisps, the variable-value pairs are not themselves enclosed in parentheses.

In this code:

    (let (latitude longitude) (func1 a b c)
We're not binding latitude to the value of longitude, but binding that whole thing to the return value of (func1 a b c).

A simpler example:

    (let (name score) '("Steve Wiebe" 1064500)
      (prn name " was the first person to score over a million points in Donkey Kong, with a score of " score))
This prints:

    Steve Wiebe was the first person to score over a million points in Donkey Kong, with a score of 1064500

reply

3 points by jsgrahamus 3 days ago | link

And, of course, the "regular" form of arc has no parentheses:

  arc> (let hat 5 (prn "hat = " hat))
  hat = 5
  "hat = "
  arc>

reply

2 points by jsgrahamus 3 days ago | link

I thought that let looked odd, because I thought that with a let in arc, you had 1 variable/value pair. Thanks, zck, for pointing out the difference. And thanks, akkartik, for repeatedly telling me this.

reply

2 points by waterhouse 12 hours ago | link

The corresponding macro in Common Lisp has an 18-character name.

  ; SBCL
  * (destructuring-bind (x y) '(1 2) (+ x y))
  3
  ; Arc
  arc> (let (x y) '(1 2) (+ x y))
  3

reply

2 points by jsgrahamus 5 days ago | link | parent | on: Odd errors

Another odd error:

  C:\Users\Steve\Documents\arc3.1>racket -f as.scm
  Use (quit) to quit, (tl) to return here after an interrupt.
  arc> ;; Get rid of rows-tried entries for column col
  (def remove-column-number-from-rows-tried (column-# rows-tried)
       (with columns-rows -1 list1 (rev rows-tried) list2  '()
             (for i 1 (len rows-tried)
                  (= columns-rows (pop list1))
                  (if (~is (car columns-rows) column-#)
                      (push columns-rows list2)))
             (rev list2)))
  Error: "Can't take cdr of columns-rows"
  arc>

reply

2 points by akkartik 5 days ago | link

You need parens around the variable bindings in with, otherwise Arc can't tell where bindings end and the body begins.

  (with (columns-rows  -1
         list1  (rev rows-tried)
         list2  '())
    ..)

reply

1 point by jsgrahamus 5 days ago | link

FWIW, rows-tried is a list of lists.

reply

2 points by jsgrahamus 5 days ago | link

Thank you.

reply

2 points by jsgrahamus 5 days ago | link | parent | on: Odd errors

Thanks, zck!

reply

1 point by zck 5 days ago | link

No problem! Glad to help.

reply

2 points by jsgrahamus 5 days ago | link | parent | on: Odd errors

Will anarki run on Windows?

reply

1 point by akkartik 5 days ago | link

I did see it running momentarily on Windows a few weeks ago: http://arclanguage.org/item?id=19458. It might have a few issues, but if you report them I'll try to fix them.

reply


How did you know that (n-of) was a function? Where is there a list of all the functions in arc?

reply

1 point by akkartik 5 days ago | link

Discoverability is a perennial issue. Arc 3.1 is pretty comprehensively documented at https://arclanguage.github.io/ref (even if it's a lot to read). n-of is in the page on list operations: http://arclanguage.github.io/ref/list.html Unfortunately changes to Arc 3.1 in Anarki are harder to find; nobody's gotten around to building a copy of Ken Shirriff's reference for Anarki. One good place to the first order is the https://github.com/arclanguage/anarki/tree/master/CHANGES directory on Github.

reply


Thanks, zck.

Didn't know there was a built-in function, so tried creating one on my own.

  arc> (def make-list (size val)
         (let alist nil
           (def make-list2 (alist size val)
             (if (is size 0)
               alist
               (make-list2 (cons val alist) (- size 1) val)))
           (make-list2 alist size val)))
  *** redefining make-list
  #<procedure: make-list>
  arc> (make-list 5 -1)
  *** redefining make-list2
  (-1 -1 -1 -1 -1)
  arc>
Comments?

reply

2 points by jsgrahamus 6 days ago | link

Shouldn't be redefining, right?

This seems better:

  arc> (def make-list (alist size val)
         (if (is size 1)
           (cons val alist)
           (make-list (cons val alist) (- size 1) val)))
  #<procedure: make-list>
  arc> (make-list nil 5 -1)
  (-1 -1 -1 -1 -1)
  arc> (make-list nil 11 -1)
  (-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1)
  arc> (make-list nil 111 -1)
  (-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1   -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1   -1 -1 -1 -1 -1
   -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1   -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1   -1 -1 -1 -1 -1
   -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1   -1 -1 -1 -1)
  arc>
But I shouldn't have to invoke make-list with a nil list to begin with.

reply

2 points by zck 6 days ago | link

> But I shouldn't have to invoke make-list with a nil list to begin with.

You can use a helper function:

    (def make-list (size val)
         (make-list-helper nil size val))
    
    (def make-list-helper (alist size val)
         (if (is size 1)
             (cons val alist)
           (make-list-helper (cons val alist) (- size 1) val)))
But this clutters up the namespace. We can use a local helper function to move make-list-helper inside the body of make-list, and wrap it in afn to make it able to recurse.

    (def make-list (size val)
         (let helper (afn (alist size val)
                          (if (is size 1)
                              (cons val alist)
                            (self (cons val alist) (- size 1) val)))
              (helper nil size val)))

reply

2 points by akkartik 6 days ago | link

Yes you don't need the nil argument. Since make-list returns a list, do the conses on the way out of recursive calls rather than on the way in:

  (def make-list (size val)
    (if (> size 0)
      (cons val
            (make-list (- size 1) val))))
This is identical to your version, except I dropped the now-unnecessary base case (if now generates the initial list at the bottom-most recursive call) and moved the cons outside the call to make-list.

reply

2 points by jsgrahamus 6 days ago | link

Great. Still wrapping my head around recursion.

Thanks.

reply

1 point by akkartik 6 days ago | link

I'm surprised by the redefinition warnings. They don't happen for me. Perhaps you have some of your own code being loaded? Or maybe you have an old version? (Though I don't remember make-list ever being a thing.)

reply

2 points by jsgrahamus 6 days ago | link

I'm caught. Still using the old version of arc 3.1 on Windows 7 with racket.

reply


I believe that Kent Dybvig, author of The Scheme Programming Language, was one of the chief creators of ChezScheme. Over the years I heard good things about it, chiefly that it was very fast. Also the full version was expensive (~$1,000), although they did have a free interpreter (Petite ChezScheme). With the sale of it a few years ago, it seemed to disappear from view: E-mails to Cisco would not receive replies.

Seems to be quite good news that it is now open source. Wonder if arc would run under it and if it would be faster?

reply

1 point by akkartik 6 days ago | link

I played with Petite Chez Scheme back in '99-'00, long before I knew much about Lisp. Very cool blast from the past.

reply

3 points by jsgrahamus 11 days ago | link | parent | on: Language Opinions

My workday language, MUMPS, also treats everything as a string, unless a number is needed, in which case it tries to coerce the string into a number.

I do find coding easier in MUMPS. Surely that has nothing to do with 30 years of coding in it or my brain having been rewired for it...

reply

More