Arc Forumnew | comments | leaders | submitlogin
2 points by proponent 5561 days ago | link | parent

Thanks much for your detailed and informative reply. I like your suggestion about changing to 'table to take variable numbers of arguments.


2 points by palsecam 5558 days ago | link

> I like your suggestion about changing to 'table to take variable numbers of arguments.

Then let's do it :-)

In ac.scm, we change the xdef of 'table, and the def of 'fill-table (which doesn't seem to be used anymore) to work with a normal list (and not an alist).

   (xdef table (lambda args
	         (let ((h (make-hash-table 'equal)))
		   (if (pair? args)
		       (if (pair? (cdr args))
			   (fill-table h args)
			   ((car args) h)))
		   h)))

   (define (fill-table h lst)
     (if (pair? lst)
         (begin (hash-table-put! h (car lst) (cadr lst))
	        (fill-table h (cddr lst)))
         h))
Then we have what we want:

  arc> (table)
  #hash()
  arc> (table [for i 0 3 (= _.i 42)])
  #hash((3 . 42) (0 . 42) (1 . 42) (2 . 42))
  arc> (table 'a 2 'b 42)
  #hash((b . 42) (a . 2))
(Warning: lightly tested)

> Thanks much for your detailed and informative reply.

Thanks go to you for having a fresh view on the data structures of Arc, and questioning them. I was just "quoting the manual" and this is not hard.

----

To absz: thanks for mentioning "DWIM", I didn't know this acronym but this is exactly what I expect from a (programming) language. It is what differenciates a language from a (formal) notation IMO. Funny point, the (french) wikipedia article uses Perl as a DWIM-oriented language example :-)

Interesting that Thaddeus (http://www.arclanguage.org/item?id=10533) makes a mistake using 'obj / wants 'inst to work w/ 'obj. This comforts me in the idea that 'obj is confusing. People expects an "object" to do magic (inheritance, instanciation, etc), to be high-level, where they just expect an (hash)"table" to be a simple key/value store.

The DWIM definition of 'table given above would be even better if it could also take an alist as single argument, and use it to init the table (it's easily doable, but I'm tired now).

-----

1 point by palsecam 5558 days ago | link

But maybe this DWIM stuff is crap because we're writing everything in Scheme and not in Arc.

Maybe (xdef new-table (lambda () (make-hash-table 'equal)), and then use the raw 'new-table and 'fill-table, 'listtab, 'tablist and co. to define a DWIM 'table in Arc.

Or maybe it's crap because DWIM is crap by nature and it's better to have (to know) 'table, 'obj, 'fill-table, etc.

What is sure is that it makes the "design work" easier, you can keep the 'table/etc. definitions shorter and cleaner in arc.arc/etc. What is less sure is if doing so (making the designer have the good life) is the way to have a pratical language for actual programmers.

-----

1 point by conanite 5558 days ago | link

I like your definition of table. The only advantage of 'obj is that keys don't need to be quoted. (Although sometimes that's a disadvantage too; the macro quotes them, so keys can't be determined at run-time)

-----