Arc Forumnew | comments | leaders | submit | parenthesis's commentslogin
2 points by parenthesis 6455 days ago | link | parent | on: REPL variables

Spot the missing quote, should be

  (arc-eval `(output-history-update ',val))
not

  (arc-eval `(output-history-update ,val))

-----

1 point by sjs 6455 days ago | link

You should update the original post.

-----

2 points by parenthesis 6455 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 parenthesis 6455 days ago | link | parent | on: Implementation of ac.scm for SBCL

If nothing else, I hope this will help me to understand the original scheme ac.scm (my background is CL rather than scheme). Thanks!

-----

1 point by parenthesis 6456 days ago | link | parent | on: Alphabetical List of Arc Functions

Yes:

  (sort (fn (x y) (< (coerce x 'string) (coerce y 'string))) (keys sig))
(As it says in the link, first comment out

  ;(aload "libs.arc")
in as.scm for just the basic arc.arc functions and macros.)

-----

4 points by hakk 6456 days ago | link

Shorter:

    (sort (compare < [coerce _ 'string]) (keys sig))

-----

4 points by fallintothis 6455 days ago | link

Shorter:

  (sort < (keys sig))
< compares symbols as it would strings.

-----

3 points by parenthesis 6456 days ago | link | parent | on: "procedures" vs "functions"

It's just because it's mzscheme doing the printing: that's how it does it. Functions are called 'procedures' in scheme. But they are called 'functions' in Arc.

-----

3 points by parenthesis 6457 days ago | link | parent | on: Weak reduce

The current reduce is fine if the given function can take 0,1 or 2 arguments. E.g.

  (reduce + ()) -> 0
  (reduce + '(1)) -> 1
But if you were using, e.g.

  (def add (x y)
    (+ x y))
then the above cases wouldn't work.

But if reduce is redefined thus:

  (def reduce (f xs)
    (if (cddr xs) (reduce f
                          (cons (f (car xs) (cadr xs))
                                (cddr xs)))
        (cdr xs) (apply f xs)
        xs (car xs)
        nil))
Then

  (reduce add ()) -> nil
  (reduce add '(1)) -> 1

-----

4 points by simonb 6457 days ago | link

A somewhat messy attempt at mimicking CL's reduce:

  (let init-default (uniq)      
    (def reduce (f xs (o init init-default))
      ((afn (xs) 
         (if (cddr xs) (self (cons (f (car xs) (cadr xs)) (cddr xs)))
             (cdr xs) (apply f xs)
             xs (car xs)
             (f)))
       (if (is init init-default) xs (cons init xs)))))
For reference:

"In the normal case, the result of reduce is the combined result of function's being applied to successive pairs of elements of sequence. If the subsequence contains exactly one element and no initial-value is given, then that element is returned and function is not called. If the subsequence is empty and an initial-value is given, then the initial-value is returned and function is not called. If the subsequence is empty and no initial-value is given, then the function is called with zero arguments, and reduce returns whatever function does. This is the only case where the function is called with other than two arguments."

http://www.lispworks.com/documentation/HyperSpec/Body/f_redu...

-----

1 point by icemaze 6457 days ago | link

True, but sometimes you want some particular value for those special cases. In case of a sum (reduce add ()) should return 0, which is the (mathematically) "right" result.

Is there a way to know the arity of a function?

-----

1 point by parenthesis 6457 days ago | link

Yes, I suppose the real solution is an optional initial value argument (as in CL reduce)), thus you can provide an appropriate identity value (e.g. 0 in the case of add).

Edit: as simonb has simultaneously given.

-----


... and it's ascii!

-----

1 point by parenthesis 6457 days ago | link | parent | on: Show us your Arc code

  (def prime (n)
    (if (~isa n 'int) nil
        (< (= n (truncate n)) 2) nil
        (is n 2) t
        (multiple n 2) nil
        (with (div 3
               lim (truncate (sqrt n))
               result t)
          (while (and (or (~multiple n div)
                          (= result nil))
                      (< div lim))
            (++ div 2))
          result)))

-----

1 point by parenthesis 6455 days ago | link

-- Actually, spot the bug!

-----

2 points by parenthesis 6458 days ago | link | parent | on: I hereby propose...

Yes, one who Arcs is 'an Arcist'.

-----

10 points by nandosperiperi 6457 days ago | link

lisp hacker -> arc welder

-----

2 points by spanky575 6457 days ago | link

or arc wielder

-----

10 points by parenthesis 6458 days ago | link | parent | on: Clarification about Character Sets

I, for one, endorse your approach of getting the foundations right before building towers atop.

I venture in explanation of the character set controversy: IIRC You have written of wanting Arc to be good specifically for web programming. (And obviously you are using it thus.) Ascii is fine when working on code to do symbolic differentiation (as I believe McCarthy was interested in at the dawns of time). But for a web app for the Chinese market, say, Unicode is obviously going to be involved. I think perhaps people were just expecting 'new web-app language' to entail Unicode support.

-----

7 points by metageek 6458 days ago | link

"I think perhaps people were just expecting 'new web-app language' to entail Unicode support." -- I would go further: I would say that many of us consider Unicode support an essential; it's part of getting the foundations right. PG mentioned hearing/reading Guido talk about the pain of switching Python's character support--but what was painful was the switching, not the character sets. The sooner Arc makes that switch, the less pain it'll be.

-----

4 points by lg 6458 days ago | link

I think he said it was painful for Guido because he had to worry about backwards-compatibility...and that won't be an issue for Arc.

-----

3 points by metageek 6457 days ago | link

It might. PG has decided not to worry about the pain of backwards compatibility for other people's code; but he still has to consider his own code.

-----

1 point by Gotttzsche 6457 days ago | link

He said that, but didn't they decide to break the backwards-compatibility with Python3000?

-----

4 points by parenthesis 6458 days ago | link | parent | on: Any way to write standalone scripts?

In file script.arc :

  (prn "Hello, you know!")
  (quit)
In file script :

  #!/bin/bash
  mzscheme -m -f as.scm  < script.arc
(Putting /.../as.scm if necessary.)

Then

  chmod +x script
And

  ./script

-----

2 points by scav 6457 days ago | link

Hmm. Problem is, that means stdin is your arc script. For many scripting tasks, you want stdin to be the input to your script, e.g. a pipe or console or redirected file.

-----

1 point by offby1 6458 days ago | link

I got no problem with that, if it works! Thanks

-----

2 points by apotheon 6458 days ago | link

Any way to do it that isn't a hideous hack?

-----

More