Arc Forumnew | comments | leaders | submit | zhtw's commentslogin
3 points by zhtw 5207 days ago | link | parent | on: Named loop or continue keyword?

ccc is certainly way to go, but just in case: mzscheme does not use continuation passing style so the ccc can work much much slower than just a function call because it copies the stack.

Actually I didn't do the profiling so maybe there is nothing to worry about.

-----

3 points by fallintothis 5207 days ago | link

  arc> ; with ccc
  (time
    (with (x 0 y 0)
      (while (< x 1000000)
        (catch
          (when (odd x)
            (++ x)
            (throw))
          (++ y)
          (++ x)))
      (list x y)))
  time: 27208 msec.
  (1000000 500000)

  arc> ; without ccc
  (time
    (with (x 0 y 0)
      (while (< x 1000000)
        (if (odd x)
            (++ x)
            (do (++ y)
                (++ x))))
      (list x y)))
  time: 1978 msec.
  (1000000 500000)
Interesting observation!

-----

1 point by zhtw 5452 days ago | link | parent | on: Confusing types: string port and file port

> "how would that help me write programs more concisely?"

Ok. This is after all the most relevant question.

But my point is although it's not necessary to worry about the difference between outport and outfile from the user's point of view, it's certainly impossible to ignore them when you implement these functions. You kind of have to since you need to know whether or not inside is allowed for a particular object. Whether to make this information visible for the user is another question.

-----

1 point by zhtw 5485 days ago | link | parent | on: A Lisp Concise: 'while' in arc and eight

Is it possible to write definitions like (def f ('a b) <body>) and what would be the meaning?

-----

1 point by diiq 5485 days ago | link

Yes --- that's the best part! For instance, the example aif I gave uses a mixed quoted/unquoted lambda list.

For an example of the exact form you gave:

    (def f ('a b) (print a) (print b))
    (f (list 1 2) (list 3 4))
Outputs:

    (list 1 2) 
    (3 4)
Any combination of quoted and unquoted arguments is valid. Those that are quoted act like macro arguments, and those that are unquoted act like functional arguments.

-----

3 points by zhtw 5503 days ago | link | parent | on: A bug in assign?

Yeah, but shouldn't it be changed to nil?

  (define (ac-set x env)
    (if (null? x)
       (list 'quote 'nil)
       `(begin ,@(ac-setn x env))))
I realize that it's not very important but still it's a bug. No?

-----


I don't understand how there cannot be lookup in both cases. The only difference I can guess is that in case of hashes you might have used strings as keys and when using symbols the lookup is done only by pointers. But that's the same in scheme if use use symbols as keys in hash table.

-----

3 points by conanite 5526 days ago | link

zhtw, your profile says you're building a lisp compiler, so I'm taking the liberty of exposing the innards of rainbow a little, it might be helpful:

  public class Symbol {
    String name;
    ArcObject value;

    // ... etc
  }
Pieces of arc code contain direct references to these Symbol objects. For example, (car x) is implemented by something like this:

  class Invoke_Sym_Lex {
    Symbol fn;            // points to the "car" symbol
    LexicalSymbol arg;

    public void invoke(...) {
      fn.value.invoke(arg);
    }
  }
there is no lookup. The symbol is baked into the code. Lexically-bound symbols are more complicated, but they don't use hashes for lookup either.

As far as I can tell, this approach will support namespaces without any performance penalty, except perhaps at read/compile-time. Assuming arc gets namespaces one day ...

-----

1 point by zhtw 5526 days ago | link

Interesting. I'm sure there is no need to do a lookup for symbols in local scope. But we're talking about globals.

What about this:

(eval (coerce "car" 'sym))

-----


Yes, I understand that. And that's why I asked the question. Conanite said that it might be for performance reason. Do you think it is?

-----

1 point by zhtw 5528 days ago | link | parent | on: Other sites running news.arc?

Somebody already asked this. I'm using news.arc: http://forum.zhtw.org.ru

-----

3 points by zhtw 5594 days ago | link | parent | on: Starting up with Arc

If you're interested here is my startup script. It defines "import" macro which is the same as "load" but path is treated related to arc base prefix. "arc" is the startup script itself. Options -l allows to load arc-file before prompth. "boot.scm" is my replacement for as.scm.

arc: #!/bin/sh

  mzscheme=/usr/local/mzscheme372/bin/mzscheme
  pkgbase=/home/avl/pkg

  prog=""

  while [ "$#" -gt 0 ]; do
    if [ "x$1" = "x-l" ]; then
      shift
      [ -f "$1" ] || { echo "No such file ($1)"; exit 1; }
      loadstr="$loadstr (load \"$1\")"
      shift
    else
      [ -f "$1" ] || { echo "No such file ($1)"; exit 1; }
      prog="$1"
      shift
    fi
  done

  if [ -z "$prog" ]; then
    ( echo "$loadstr"; cat; echo " (quit)" ) |
      ( "$mzscheme" -m -f "$pkgbase/arc/boot.scm"; echo )
  else
    ( echo "$loadstr"; echo "(load \"$prog\") (quit)"; ) |
      exec "$mzscheme" -m -f "$pkgbase/arc/boot.scm"
  fi
boot.scm:

  (require mzscheme) ; promise we won't redefine mzscheme bindings

  (define arcbase "/home/avl/pkg/arc/arc3")
  (define arclibs "/home/avl/pkg/arc/lib")

  (define current-dir (path->string (current-directory)))
  (current-directory arcbase)

  (require "arc3/ac.scm") 
  (require "arc3/brackets.scm")
  (use-bracket-readtable)

  (aload "arc.arc")
  (aload "libs.arc") 

  ;(xdef 'curdir current-directory)
  ;(xdef 'pkgbase arclibs)

  (current-directory "/home/avl/pkg/arc")
  (aload "init.arc")
  (current-directory current-dir)

  (tl)
init.arc:

  (load "import.arc")
import.arc:

  ; import is the the same as load but path is threated related to pkgbase

  (def namechain->path (l)
    (tostring (each x l (pr "/" x))))

  (mac import namechain
    `(load (string pkgbase (namechain->path ',namechain) ".arc")))

  ; (import sys stream) -- that's my personal stuff.
So you just need to substitute /home/avl/pkg/arc with the path where your arc3 dir is placed.

And one last thing. If you install rlfe it's convenient to rename "arc" to "real-arc" and start it by "/usr/bin/rlfe real-arc" from "arc".

Hope this will be usefull.

-----

1 point by edeion 5592 days ago | link

Thank you! I'm not using it right now, but it may come in handy sooner or later.

-----

3 points by zhtw 5658 days ago | link | parent | on: Any other arc news forums out there?

http://forum.zhtw.org.ru/

Why?

-----

1 point by thaddeus 5657 days ago | link

Nice. Thanks. I think that's Russian correct? (pardon if I got it wrong).

I'm just curious. Although I don't use hacker news much (can't relate to the topics as much) - I can see how the layout and usage is much better than most sites I visit. And I can see a mutlitude of uses for it - not just news. So I am just surprised I haven't seen more of them. I was thinking about starting one up for my industry peers (not the hackers).

Just wanted to see what other members experiences were. T.

-----

1 point by zhtw 5657 days ago | link

> Nice. Thanks. I think that's Russian correct?

Yep.

And I'm too using it not because it's written in Arc, but because it just looks good.

-----


The really good idea would be to rewrite all the code from the book in Arc. I love the book and I don't know Common Lisp. The book would be much clearer with examples written in Arc. For example generalized variables: I didn't even read examples from the book, I read the Arc source instead.

-----

2 points by anarcer 5660 days ago | link

Nice idea rewriting all book in Arc: OnArc!

-----

More