Arc Forumnew | comments | leaders | submitlogin
Question about alist functions in arc.arc
3 points by Adlai 5437 days ago | 2 comments
While reading arc.arc, I came across what seems like an inconsistency:

  (def assoc (key al) ...)  ;; from line 92
  (def alref (al key) ...)  ;; from line 99
I'd think that two such closely related functions should have the same syntax. Is there any specific reason why they are reversed?

(The only one I could think of off the top of my head is that both are "verb subject object" calls)

EDIT: added line numbers to the code



2 points by pg 5436 days ago | link

The vague eventual plan is to replace alref with some form of function-call like lookup, as with tables. I'm still not sure how, but in the meantime I wanted a function that at least had the same argument order.

-----

1 point by Adlai 5436 days ago | link

It be very neat for alists to be usable like tables and strings, as "functions". That would almost be like a duck-typed "database" interface. Obviously some functionalities are specific to each (shadowing older pairs in an alist, having five bazillion keys in a hash table), but it would make sketching out an application much easier -- you could change only one or two spots in your code to switch between a table or alist, and the rest of your code would still work fine. Maybe this could be another use for 'annotate -- to differentiate between "a list" and "an alist"?

In the meantime, it should be easy to write a "polymorphic" lookup function:

  (def lookup (db key)       ; obviously just a sketchy
    (if (atom db) (db key)   ; definition -- but Arc is LFSP
        (alref db key)))     ; so there's no warranty :)

-----