Arc Forumnew | comments | leaders | submit | zhtw's commentslogin
1 point by zhtw 5820 days ago | link | parent | on: Request for Bugs

Implementation details of lists are not transparent. Sometimes I can access an element of a table by '(a) but not by (list 'a) which is the same.

Details: http://arclanguage.com/item?id=6985

-----

1 point by zhtw 5818 days ago | link

This duplicates the one from here: http://arclanguage.com/item?id=9151

Sorry.

-----

1 point by zhtw 5820 days ago | link | parent | on: Request for Bugs

Expressions that need ssexpand (with . and !) don't work in some context:

  (let lst (list (table))
    (= (lst.0 'key) 'value))
Error: "Can't invert ((lst 0) (quote key))"

http://arclanguage.com/item?id=8287

-----

1 point by zhtw 5818 days ago | link

This seems fixed by you patch from here: http://arclanguage.com/item?id=9215

Thanks.

-----

3 points by zhtw 5820 days ago | link | parent | on: Request for Bugs

I think that memo should remember the result of the function even if it (the result) was nil. Now it uses hash tables which don't store nils. It would be possible then to be sure that a function won't be called twice it if was wrapped by memo (I used memo for that purpose.)

Here is the discussion: http://arclanguage.com/item?id=8667

-----

4 points by pg 5815 days ago | link

Good idea; fixed:

    (def memo (f)
      (with (cache (table) nilcache (table))
        (fn args 
          (or (cache args)
              (and (no (nilcache args))
                   (aif (apply f args)
                        (= (cache args) it)
                        (do (assert (nilcache args))
                            nil)))))))

-----

2 points by zhtw 5973 days ago | link | parent | on: Does memo work right?

Actually I know why it happens and how to fix that. The question was more like "is it a bug or a feature?" I remember that PG suggested (but forgot where I read that) to store cons' in a table when you need to distinguish nil and absence of an element but why doesn't he use that technique (or any other) himself?

-----

2 points by skenney26 5973 days ago | link

I think the simple answer is that he hasn't needed that feature. 'memo and 'defmemo are used in 5 places in news.arc and it doesn't look like any of those uses would benefit from allowing nil as a value.

If someone created an application that benefited from that feature then perhaps there would be reason to redefine 'memo.

This seems to be an important part of the Arc philosophy: add a feature only when its absolutely needed.

-----

1 point by zhtw 5970 days ago | link

Only now I realized that you treat memo as some kind of the way to improve performance (do you?). What I used memo for is to make sure that function won't be called twice:

  (mac delay (e)
    `(memo (fn () ,e)))

  (def force (d) (d))
When I use lazy sequences (of symbols read from input port for example) based on these definitions I can't be sure that readc somewhere inside will never be called twice if I call force for an element of this sequence twice.

So I treat this as a bug. Or maybe I'm just wrong about what memo is for at all. Am I?

-----

1 point by aaronla 5959 days ago | link

I'd venture to guess that memo creates a new cache for each invocation, so two calls

  (map (lambda (f)  ;; invokes f 3 times
               (f) (f) (f) )
       (list (delay (foo bar)) 
             (delay (foo bar))))
I think thiw will call foo exactly twice, because each memo invokation produces a new cache, but I may be mistaken.

[pardon the syntax... this is in scheme. i have only just installed arc and (def hello-world ...) is as far as i've gotten]

-----

1 point by absz 5959 days ago | link

The real problem is that if you do

  (let d (delay (foo bar))
    (force d)
    (force d))
, then there's no guarantee that (foo bar) will be run exactly once---if (foo bar) returns nil, then it won't be cached.

-----


Yes. So now I really have to switch to your branch of Arc. (Just didn't want to do it while everything was working in originall Arc2.)

-----

2 points by zhtw 6069 days ago | link | parent | on: FreeBSD deployment experiences

FreeBSD was the first platform I got arc working on. I didn't start application server but I don't think I would have any problem with it. Now I switched to Ubuntu on my laptop (I've been using FreeBSD for about 4 years.) because FreeBSD crashes when I accidentially remove a USB mass storage device without unmounting it. Except this and some minor problems I had no problems with it.

-----

2 points by zhtw 6166 days ago | link | parent | on: How does hash table work when key is a list?

Thanks for the detailed explanation. I got the idea. Well, in my case this is going to stay deep inside the library. So any workaround would be fine.

But I solved this by adding (join ... nil).

-----

2 points by absz 6166 days ago | link

That is a much nicer in-Arc solution than mine; good catch. In any case, I'm glad I could be of assistance.

-----

5 points by zhtw 6173 days ago | link | parent | on: The Russian translation of the Arc tutorial.

The translation of the whole tut is ready. TeX-source and pdf are here:

  ftp://ikemefuna.zhtw.org.ru/pub/doc/arc,
  ftp://ftp.zhtw.org.ru/pub/doc/arc.
They are not 24x7-available but intersection of downtime must be not big.

-----

3 points by absz 6173 days ago | link

I don't speak Russian myself, but I want to thank you for the effort—it's important to get stuff published only in English available more broadly.

-----

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

That explains everything. Thanks!

-----

2 points by zhtw 6176 days ago | link | parent | on: Don't understand how macros work

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 6175 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 6175 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 6175 days ago | link

This is correct ^^

-----

2 points by zhtw 6175 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.

-----

More