Arc Forumnew | comments | leaders | submit | cchooper's commentslogin

It would be really nice just to know what's going on, even if the answer is "Not for a long time because..."

-----

5 points by cchooper 6316 days ago | link | parent | on: Interpreter Manipulation?

I think this is a great idea, and should be a standard feature for anything that calls itself a 'reprogrammable programming language'. After all, the ultimate in reprogramability is being able to recode the interpreter itself.

I have a different suggestion for implementing it: instead of redefining the interpreter, have a macro that is called on every expression before it's interpreted. The macro would compile the expression down to canonical Arc, which could then be executed by the standard interpreter. Not sure what the pros/cons are of doing it that way, but it sounds to me like an easier hack than redefining the Scheme function.

-----

4 points by cchooper 6324 days ago | link | parent | on: Don't understand how macros work

All macros in an expression are expanded before any part of the expression is executed. So (assign k (h k)) will be expanded before each is executed, and at that point k has no value, so (eval k) will fail.

So you need to move eval into the result of the macro expansion, and avoid calling it in the macro expansion itself:

  (mac assign (name expr) `(eval (list '= ',name ',expr)))

-----

2 points by zhtw 6324 days ago | link

OK. I understood the problem. But your solution doesn't work.

  arc> (= x 'var)
  var
  arc> (assign x 20)
  20
  arc> var
  Error: "reference to undefined identifier: _var"
Indeed. What you wrote is "assign a value to the given name". I meant "to assign a value to a variable which name is stored in the given variable".

My original example was just attempt to copy the table into the current environment:

  (= h (obj name0 0 name1 1 name2 2))
  (each x (keys h)
    (assign x (h x)))

-----

3 points by almkglor 6323 days ago | link

Then use 'eval :

  (ontable k v h
    (eval `(= ,k ,v)))
Note that this does not copy to the current environment, just the global environment. So if you're doing something like this:

  (let foo 42
    (= h (table 'foo 1)) ; Anarki only
    (ontable k v h
      (eval `(= ,k ,v)))
    foo)
Then the 'foo you access is the local one, but the one written by 'eval is the global.

-----

3 points by absz 6323 days ago | link

Careful! You're evaluating the value of v here, which can break:

  arc> (ontable k v (table 'var 'a)
         (eval `(= ,k ,v)))
  Error: "reference to undefined identifier: __a"
You need to quote the value of v here to prevent it from being evaluated; when you do so, you get

  arc> (ontable k v (table 'var 'a)
         (eval `(= ,k ',v)))
  #hash((var . a))
  arc> var
  a
And then the body of he loop is the same as the body of my assign function from http://arclanguage.org/item?id=6918.

-----

1 point by almkglor 6323 days ago | link

This is correct ^^

-----

2 points by zhtw 6323 days ago | link

> Note that this does not copy to the current environment, just the global environment.

Yeah, I'm aware of that. But it's a good point anyway, thanks.

-----

2 points by stefano 6324 days ago | link

You don't really need to use eval:

  (mac assign (name expr)
    `(= ,name ,expr))
then (assign k 3) will be expanded to (= k 3).

-----

2 points by zhtw 6324 days ago | link

No. You didn't understand. I meant exactly what I wrote. I want to assign a value to variable which name is stored in the variable "name".

-----

1 point by cchooper 6344 days ago | link | parent | on: Suggestion for two core features

Really? I thought easy list concatenation was the better idea. Arc is a list-based language, and concatenation is a very basic list operation, so I thought it would be a good thing to optimise it as much as possible.

-----

6 points by cchooper 6345 days ago | link | parent | on: (/ 0 0.0) = 0

To be pedantic, it doesn't make any sense to return 0.0, but it does make some sense to return 0. I'm sure that's what you meant though.

It's 0.0/0.0 that gets my head spinning. If only 'Whatever' were a valid number.

-----

1 point by cchooper 6347 days ago | link | parent | on: defmacro mac?

yep

-----

1 point by cchooper 6352 days ago | link | parent | on: MySQL needed?

You could use Arc templates, which are an easy way of saving and loading Arc objects to/from text files. That's what this forum uses. I believe kens' site has some documentation for this, or you could look at the news.y source code.

If you want to use a SQL database instead, someone wrote an interface for it and posted it to the forum (maybe also on Anarki?) but I can't find it with Google.

-----

1 point by globalrev 6352 days ago | link

where is the news.y sourcecode? couldnt find it googling and not on the arc or anarki homepages.

-----

2 points by lojic 6352 days ago | link

It's in the tarball as news.arc

-----

2 points by cchooper 6352 days ago | link | parent | on: Arc webapp invaded by ruby!

It looks like some Ruby program has dropped a cookie. defop-raw will bring back all cookies created by localhost, so perhaps you've been running some Ruby web service from your machine?

The solution is to clear out your cookies.

-----

2 points by cchooper 6359 days ago | link | parent | on: Suggestion for two core features

Definitely like that idea. Using is is a real pain and I have to use it all the time.

-----


Just to add: if you want your function to take any number (including zero) arguments, then just use a symbol instead of an argument list, and all the arguments will be bound to that symbol.

  (def return-all-args x x)

  (return-all-args 1 2 3)
  => (1 2 3)

-----

1 point by krg 6355 days ago | link

globalrev, this stuff confused me at first too.

So if you have (def foo (a b . c) ...stuff...) and you call (foo 1 2 3 4 5), a is bound to 1, b is bound to 2, and c is bound to the list (3 4 5).

And (def foo a ...stuff...) is just shorthand for (def foo ( . a) ...stuff...). So calling (foo 1 2 3) in this case means a is bound to the list (1 2 3).

-----

3 points by almkglor 6355 days ago | link

> And (def foo a ...stuff...) is just shorthand for (def foo ( . a) ...stuff...).

Technically wrong: ( . a) is invalid syntax. However it does help to think of it that way.

-----

More