Dan Haffey
2016-07-19 02:42:40 UTC
As mentioned in talk earlier, it'd be nice if there was a way to bind local
aliases when pattern-matching ("fishing"?):
=+ a=`(unit)`[~ 42]
?+ a ~
{* b/*}
`+(b)
==
Currently, it appears that faces in the mold being tested do make their way
into the scrutinee's type, but they get inserted underneath any existing
faces, rendering them practically useless. To use b in the above example
you'd have to write b.u.a.
This seemed like something that could be implemented as a combined
"if-fits" macro, since it would have access to both the mold and the yes
branch. The idea being that ?- and ?+ would use the new macro instead of
?:(?=(...)). Eg, if the new rune was ?%, then this:
?% {* b/*} a
[%yes b]
%no
would expand to:
?: ?=({* *} a)
=* b +3:a
[%yes b]
%no
I hacked up a naive proof-of-concept expansion
<https://gist.github.com/dhaffey/2ee9e7bf712c6a2fc5c10c037d7eced8>. It
hijacks :^ to stand in for the new rune, since it wants four sub-twigs and
testing is easier with something ream-able. It only binds faces appearing
in a literal mold, which can be viewed as a bug or a feature. Seems like a
feature to me, binding locally-sourced names is the whole point and fishing
with faces is otherwise fairly pointless.
So it is doable as a macro, but only for certain values of "do". The
problem with that expansion is that it preserves faces already present at
the aliased axis. Not really an issue for atoms, but if you wanted to
access foo.bar.b you'd be out of luck on account of the original u= face
provided by unit. You'd have to write foo.bar.u.b instead, blegh. (There's
actually more interference in my implementation because I didn't bother
scraping faces out of the mold before handing it off to ?=, but that
wouldn't be hard to do.)
So a proper treatment probably requires deeper compiler integration, at
least enough to allow the alias to drill down through any faces present at
the axis. Which sounds like a fun project, but a bit much to bite off
without getting some feedback on the basic idea and approach first. (And
I'm ++knee-deep in a regex implementation I'd like to finish to before
digging into an area as context-heavy as the compiler.)
Anyone interested in something like this existing? And/or implementing it?
:)
aliases when pattern-matching ("fishing"?):
=+ a=`(unit)`[~ 42]
?+ a ~
{* b/*}
`+(b)
==
Currently, it appears that faces in the mold being tested do make their way
into the scrutinee's type, but they get inserted underneath any existing
faces, rendering them practically useless. To use b in the above example
you'd have to write b.u.a.
This seemed like something that could be implemented as a combined
"if-fits" macro, since it would have access to both the mold and the yes
branch. The idea being that ?- and ?+ would use the new macro instead of
?:(?=(...)). Eg, if the new rune was ?%, then this:
?% {* b/*} a
[%yes b]
%no
would expand to:
?: ?=({* *} a)
=* b +3:a
[%yes b]
%no
I hacked up a naive proof-of-concept expansion
<https://gist.github.com/dhaffey/2ee9e7bf712c6a2fc5c10c037d7eced8>. It
hijacks :^ to stand in for the new rune, since it wants four sub-twigs and
testing is easier with something ream-able. It only binds faces appearing
in a literal mold, which can be viewed as a bug or a feature. Seems like a
feature to me, binding locally-sourced names is the whole point and fishing
with faces is otherwise fairly pointless.
So it is doable as a macro, but only for certain values of "do". The
problem with that expansion is that it preserves faces already present at
the aliased axis. Not really an issue for atoms, but if you wanted to
access foo.bar.b you'd be out of luck on account of the original u= face
provided by unit. You'd have to write foo.bar.u.b instead, blegh. (There's
actually more interference in my implementation because I didn't bother
scraping faces out of the mold before handing it off to ?=, but that
wouldn't be hard to do.)
So a proper treatment probably requires deeper compiler integration, at
least enough to allow the alias to drill down through any faces present at
the axis. Which sounds like a fun project, but a bit much to bite off
without getting some feedback on the basic idea and approach first. (And
I'm ++knee-deep in a regex implementation I'd like to finish to before
digging into an area as context-heavy as the compiler.)
Anyone interested in something like this existing? And/or implementing it?
:)
--
You received this message because you are subscribed to the Google Groups "urbit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to urbit-dev+***@googlegroups.com.
To post to this group, send email to urbit-***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to the Google Groups "urbit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to urbit-dev+***@googlegroups.com.
To post to this group, send email to urbit-***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.