til-lang / til

An easy to extend command language
56 stars 5 forks source link

Idea: use "extraction" also for setting the corresponding value #4

Closed dumblob closed 3 years ago

dumblob commented 3 years ago

It seems that e.g. for a dict the syntax for setting a value is "special" - worse, it's specific to dict and no other type.

I was thinking whether the extraction syntax could be somehow leveraged not only for reading (ranges of) values, but also generally for setting those values.

cleberzavadniak commented 3 years ago

I wouldn't use the same syntax as Extractions, but maybe using the same set syntax...

set d [dict]
set $d key value

Hey! That's not difficult to implement! set could check if argument1 is an NameAtom and, if not, call argument1.set(other_arguments). And that would benefit third-party types a lot.

dumblob commented 3 years ago

Is set extensible_to/usable_with user-defined "types" also?

cleberzavadniak commented 3 years ago

Not yet. But making it check the type of the first argument and calling firstArgument.set(...) in some cases will do the job.

cleberzavadniak commented 3 years ago

Implemented in 0.1.2.