Arc Forumnew | comments | leaders | submit | adm's commentslogin
1 point by adm 5980 days ago | link | parent | on: Ask Arc: inst or filltbl?

only difficulty was creating a list of pairs which can be used an an arg for fill-table or listtab.

  (mappend list keys vals)
is precisely what I wanted. Sorry for the caused confusion.

-----

1 point by adm 5992 days ago | link | parent | on: Help: filltbl

I wanted something like perl hash slices to build the hashtable from lists.

  (def filltbl (tbl keys vals)
    (do
        (if (no tbl) (= tbl (table)))
        (map (fn (k v) (= tbl.k v)) keys vals)
        ))
this is what I will using. Thanks again.

-----

1 point by rntz 5992 days ago | link

That'll work fine, although the 'do in your function is unnecessary. Also, there is a macro 'or= that does precisely what your first line does (assigns a value to a place if it is nil):

    (def filltbl (tbl keys vals)
      (or= tbl (table))
      (map (fn (k v) (= tbl.k v)) keys vals))

-----

1 point by thaddeus 5991 days ago | link

I'm not sure how any of these can work for intializing a table that's not aleady a table...

  (= k* '("1" "2" "3"))
  (= v* '("One" "Two" "Three"))

  assuming t* has not been set - this is what I get: 

  arc> (filltbl t* k* v*)
  Error: "reference to undefined identifier: _t*"
  
  or even:

  arc> (filltbl 't* k* v*)
  Error: "Can't set reference  t* \"1\" \"One\""

  so what am I missing ?

-----

2 points by rntz 5991 days ago | link

filltbl isn't a macro, nor does it affect the global namespace. As written, it just creates a table if its first arg is nil. Of course, this is useless unless it returns that table... oops.

    (def filltbl (tbl keys vals)
      (or= tbl (table))
      (map (fn (k v) (= tbl.k v)) keys vals)
      tbl)
IMO, a more idiomatic way to represent this would be to use optional arguments, although that requires altering the argument order:

    (def filltbl (keys vals (o tbl (table)))
      (map (fn (k v) (= tbl.k v)) keys vals))
      tbl)

-----

1 point by thaddeus 5991 days ago | link

yeah I tried passing nil in, and got nothing back, so I figured it was supposed to create the table - I should have seen that too.

-----

1 point by adm 5991 days ago | link

Can this be part of arc.arc?

-----

1 point by shader 5991 days ago | link

You could push it onto Anarki. Other than that, there isn't much you can do to get it into a public arc.arc. It seems that if a function isn't used in the forum code, pg doesn't include it in the official release.

-----

4 points by adm 5999 days ago | link | parent | on: Update: clearer +, inverse trig functions

just a thought..

  > (def isregfile ..)
  > (def isdir ..)
  > (def issymlink ..)
  > (def isdotfile ..)


  > (mac filternil ...)


  > (= goodfiles (filternil (map isdotfile&isregfile (dir "/home/me"))))
  > (= badfiles (filternil (map isdir|issymlink (dir "/home/me"))))
I prefer & over +.

-----

1 point by conanite 5999 days ago | link

Ditto for &

Unfortunately | is reserved in scheme for symbols with special characters, so isdir|issymlink would be hopelessly confusing

  arc> (assign |
  | 10)
  10
  arc> |
  |
  10
Maybe an arc implementation of 'read might overcome this.

-----

1 point by Adlai 5998 days ago | link

Or we could use ^ for disjunction.

-----

1 point by fallintothis 5998 days ago | link

But ^ is the symbol for conjunction, i.e. "and"-ing (well, not the literal caret, but the upwards-pointing symbol -- $\wedge$ in Latex). Did you mean to suggest ^ instead of +?

-----

1 point by adm 6007 days ago | link | parent | on: Compiler/translator using Arc?

option-b. Any advantages of using lisp for this than other languages?

-----

1 point by shader 6007 days ago | link

Advantages of arc:

1) powerful macros 2) functional and imperative programing 3) strong tree handling functions

Disadvantages:

1) arc is somewhat slow. 2) arc has few libraries

There might be more, but lisp is just a programming language like everything else. It might be somewhat better, but odds are it won't be a "silver bullet".

-----

1 point by Adlai 6007 days ago | link

I think that Lisp can support good quality syntax parsers. An example of this, although it's not a full fledged language, is CatDancer's JSON parser built on top of a general-purpose parser library: http://hacks.catdancer.ws/parser-combinator-approach-to-json... (it's a long article, the relevant parts are the ones about the parser-combinator approach).

Also, it seems as though your in-house language isn't completely specified yet. One area where Lisp excels is implementing unspecified things, and changing them with great flexibility on-the-fly.

Shader mentioned that Arc is slow, and this does seem to be the case. If you really want to use a Lisp, and Arc is too slow, it's probably worth looking at a few other Lisps before turning to Option A -- there are very fast implementations of both Common Lisp and Scheme.

-----