Dear Barry,
In general, I believe users are already accustomed with the classical
arrows "->" and "<-" which are used as such in quoted expressions.
But I agree that "-.>" is a very neat trick, thanks a lot. A small dot,
what a difference.
All the best,
Dmitri
On Mon, Mar 4, 2024 at 11:40?AM Barry Rowlingson <
b.rowlingson at lancaster.ac.uk> wrote:
It seems like you want to use -> and <- as arrows with different meanings
to "A gets the value of B" in your package, as a means of writing
expressions in your package language.
Another possibility would be to use different symbols instead of the
problematic -> and <-, for example you could use <.~ and ~.> which are
at all flipped or changed before you get a chance to parse your
It might make your language parser a bit trickier though. Let's see how
these things turn into R's AST using `lobstr`:
> library(lobstr)
> ast(A ~.> B)
??`~`
??A
????`>`
??.
??B
??`~`
????`<`
? ??A
? ??.
??B
You'd have to unpick that tree to figure out you've got A and B on either
side of your expression, and that the direction of the expression is L-R
R-L.
You could also use -.> and <.- symbols, leading to a different tree
??`>`
????`-`
? ??A
? ??.
??B
??`<`
??A
????`-`
??.
??B
Without knowing the complexity of your language expressions (especially
it allows dots and minus signs with special meanings) I'm not sure if A)
this will work or B) this will bend your brain in horrible directions in
order to make it work... Although you don't need to parse the AST as
you can always deparse to get the text version of it:
> textex = function(x){deparse(substitute(x))}
> textex(A <.~ B)
[1] "A < . ~ B"
The <.~ form has an advantage over the <.- form if you want to do complex
expressions with more than one arrow, since the ~ form is syntactically
correct but the - form isnt:
Error: unexpected '>' in "textex(A <.- B -.>"
Barry
On Sun, Mar 3, 2024 at 12:25?PM Dmitri Popavenko <
dmitri.popavenko at gmail.com> wrote:
This email originated outside the University. Check before clicking
or attachments.
On Sat, Mar 2, 2024 at 7:58?PM Gabor Grothendieck <
ggrothendieck at gmail.com>
wrote:
Would it be good enough to pass it as a formula? Using your
foo
foo(~ A -> result)
## result <- ~A
foo(~ result <- A)
## ~result <- A
Yes, to pass as a formula would be the idea.
It's just that the parser inverses "~A -> result" into "result <- ~A".
We are seeking for any way possible to flag this inversion.
Avi, thank you for your efforts too. Wrapping symbols into percent signs
is
an option, but as Duncan says it is much more intuitive to just quote
expression.
The challenge is to somehow flag the parser inversion, otherwise a
expression seems to be the only solution possible.
Regards,
Dmitri
[[alternative HTML version deleted]]