On Aug 28, 12:10 am, Rich Hickey <[EMAIL PROTECTED]> wrote:
> I posted a variant here:
>
> http://paste.lisp.org/display/65964
>
Rich,
It works very nicely. Thanks.
Just one thought in case the functions args are still being
decided on. Could we consider taking access path as a
vector rather than directly as function args.
Here is the use case I have in mind.
I think most access paths [:a :b :c] would be generated.
Nested structures would be something like
processor -> GPRs (general purpose regs) -> r0 r1 .. rN
-> FPRs (floating point regs) -> f0 f1 .. fN
fridge -> fruits -> apple mango ...
-> veggies -> eggplant ...
-> diary -> milk yoghurt ...
So the developer may set up something like a
(fridge-item-path (get-fruit)) => [:fruits :apple]
(processor-reg-path (get-reg-arg-from-instruction)) => [:gpr-set :r0]
With the current arg handling this is what we would need to do:
user=> (item-path :mango)
[:fruits :mango]
user=> (apply mk-get my-fridge (conj (item-path :mango) :quantity))
30
user=> (apply mk-assoc my-fridge (conj (item-path :mango) :quantity
40))
{:fruits {:mango {:quantity 40, :color :yellow},
:apple {:quantity 20, :color :red}},
:diary-products {:milk {:quantity 1, :color :white,
:type :low-fat},
:yoghurt {:quantity 10, :color :pink,
:type :strawberry}}}
[formatting added above for readability]
In case the access path were vectors the above could become:
(mk-get my-fridge (item-path :mango) :quantity)
(mk-assoc my-fridge (item-path :mango) :quantity new-quantity)
Much less noise.
Its not a big deal as the user would probably be writing a layer
on top of mk-get/mk-assoc e.g. fridge-add-item fridge-check-item
but then with access-paths as vectors it usage will be cleaner.
If you think this is a common enough case it could be considered.
Also, thanks for the [m [k & ks] v] destructuring trick. I didn't know
we could do that. Very neat.
Thanks very much.
Parth
> Rich
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---