[proposal] unification: using '() as list identity deref arg
Posted: Wed Nov 27, 2013 6:14 pm
[update] -> 10.5.6.
During writing some code to ease navigation in lists, I've stumbled about something. Let's speak code for itself.
Assumed there is a definition for ref-parent and some example list:
;; nil for non-existing parent
Now it's possible to eval:
; but it is not possible to eval:
Reason is, that:
; but:
: here '() is not being accepted as deref argument.
What about introducing '() as allowed deref argument, which dereferences list itself to which it is applied to?
Then the following would work:
This seems to be a neat unification regarding dereferencing lists by refs.
Because ref'ing a non-existing element gives:
; '() seems to be free for this purpose.
If there is:
, we get a '(). But this is no problem, because for dereferencing refs gotten this way, we have to iterate through this list, which would do nothing here.
Are there any problems with this proposal, which I don't see?
What do you think?
Feedback to this proposal is appreciated (as usual).
During writing some code to ease navigation in lists, I've stumbled about something. Let's speak code for itself.
Assumed there is a definition for ref-parent and some example list:
;; nil for non-existing parent
Code: Select all
(define (ref-parent r)
(if (null? r) nil (0 -1 r)))
;;
(setq l_nested '("1" "2" "3"
("4" "5" "6"
("7" "8" "9"))
"10" "11" "12"
("13" "14" "15"
("16" "17" "18")))
)
Code: Select all
> (l_nested (ref-parent (ref "14" l_nested)))
("13" "14" "15" ("16" "17" "18"))
Code: Select all
> (l_nested (ref-parent (ref "11" l_nested)))
ERR: missing argument
Code: Select all
> (ref-parent (ref "14" l_nested))
(7)
Code: Select all
> (ref-parent (ref "11" l_nested))
()
What about introducing '() as allowed deref argument, which dereferences list itself to which it is applied to?
Then the following would work:
Code: Select all
> (l_nested (ref-parent (ref "11" l_nested)))
("1" "2" "3" ("4" "5" "6" ("7" "8" "9")) "10" "11" "12" ("13" "14" "15" ("16" "17" "18")))
Because ref'ing a non-existing element gives:
Code: Select all
> (ref "not there" l_nested)
nil
If there is:
Code: Select all
> (ref-all "not there" l_nested)
()
Are there any problems with this proposal, which I don't see?
What do you think?
Feedback to this proposal is appreciated (as usual).