Hi, I need some help with parse please
I am trying to apply a rule in a sub-block using into but I can't figure what I am doing wrong:
rule: [ 'f set w word! (probe w) ] parse [ a b 'f c1 d [ a b 'f c2 d ] ] [ to [ rule | ahead block! into rule ] ]
I want to match both c1 and c2. Any ideas?
>> rule: [quote 'f set match word! (probe match) 'd] == [quote 'f set match word! (probe match) 'd] >> parse [a b 'f c1 d [a b 'f c2 d]][thru rule into ['a 'b rule]] c1 c2 == true
>> rule: ['f set match word! (probe match)] == ['f set match word! (probe match)] >> parse [a b 'f c1 d [a b 'f c2 d]][some thru [rule | ahead block! into ['a 'b rule 'd]]] c1 c2 == true
>> do func [x y][x * y] 2 4 == 8
>> do func [x y][x * y] 2 4 == 4 >> do reduce [func [x y][x * y] 2 4] == 8
some; second, you cannot go
into rule, because this results in failure --
into rulewould have matched your input only at the point where
rulematched it, i.e. at
'f cx. You need to go
intothe second rule - the one in which you are already. And third, you need a
skipto hop over unmatched values:
>> rule1: [ 'f set w word! (probe w) ] == ['f set w word! (probe w)] >> parse [ a b 'f c1 d [ a b 'f c2 d ] ] rule2: [ some [rule1 | ahead block! into rule2 | skip ] ] c1 c2 == true
do in context [...] 'launchI guess, or something similar, to keep
@lepinekong_twitter My previous suggestion for writing
history into file was inaccurate - it was getting history from latest to oldes, i.e. in reversed form. To get it in right order you have to reverse it beforehand. But as
reverse is modyfying command you have to
copy the history:
write/lines %history.tmp reverse copy system/console/history
To get only part of history use
copy/part system/console/history <length>. <length> may be integer! to get number of lines or,
if you want to copy from certain command, use
copy/part hist: system/console/history find hist "do %accordion.red".
To get history until certain point you ccan use
at, if you know until which line or how many line you want to get:
; e.g. until line 2, i.e. without the most recent (current) command copy at system/console/history 2 ; e.g. 10 lines from certain command found: find hist "do %accordion.red" copy/part at hist: system/console/history (index? found) - 10 found ; e.g. 10 lines from 30th command forth copy/part at system/console/history 30 - 10 10
For getting history directly into clipboard or console I didn't concieve other means than using concat:
write-clipboard copy concat reverse copy system/console/history newline
But beware, writing this to clipboard may put a huge string into your history entry, which may stall your console if you scroll backwards through history.
And finally to just print part of it on console:
print copy concat reverse copy/part system/console/history 10 newline
concat you can first
write/lines and then
read it, to get history with newlines.
There are many more ways to play with history, e.g.
probe concat take/part system/console/history 5 newline
Occasionally your history may become corrupt in the process though. :wink:
system/console/history: nodoesn't seem to break anything.
> gui-console-ctx/cfg/history == ["gui-console-ctx/cfg/history" "gui-console-ctx/history" "system/console/history" "... >> gui-console-ctx/terminal/history == ["gui-console-ctx/terminal/history" "gui-console-ctx/cfg/history" "gui-console-ctx/... >> system/console/history == false