url! value into components. See [this](https://gist.github.com/meijeru/4a44ff148e44182580c79182f61113b0) Gist.var: any [var ] approach is good, and we've all used it. I use it a *lot*. I started moving toward a default func, and still like the idea. e.g.: :comment defaulting-ctx: context [ def: func [w "Word" v "Value"][ ; We're setting one word, so don't need to use set/only. if any [not value? :w none? get w][set w :v] get w ] set 'default function [ "Sets the value(s) one or more words refer to, if the word is none or unset" 'word "Word, or block of words, to set." value "Value, or block of values, to assign to words." ][ ; CASE is used, rather than COMPOSE, to avoid the block allocation. case [ word? :word [def word :value] block? :word [ collect [ repeat i length? word [ keep/only def word/:i either block? :value [value/:i][:value] ] ] ] ] ] e.g. [ default a 1 default [a b c] [2 3 4] default f :append default [g h i j k l m] [1 2 [3] 4 5 6 7] default [g h i j k l m n o] [. . . . . . . .] ] ]
words and values blocks. It could even be spec block format./with opts [block!] approach. I have refine experiments as well, because propagating refinements was such a pain under R2. doed your defaulting-ctx: contect [.... Everything worked fine. But after trying the e.g. default [g h i j k l m] [1 2 [3] 4 5 6 7] I got the result:>> default [g h i j k l m] [1 2 [3] 4 5 6 7] == [1 2 %CyberLink%20YouCam%28Webcam%29.lnk 4 5 6 7]
word: [g h i j k l m] and value: [1 2 [3] 4 5 6 7], and tried:collect [
repeat i length? word [
keep/only def word/:i either block? :value [value/:i][:value]
]
]== [1 2 3 4 5 6 7] >> reduce word == [1 2 7 4 5 6 7]
defaulting-ctx: contect [... code, i was already >> i == %CyberLink%20YouCam%28Webcam%29.lnk
collect... i was 7.repeat wasn't capturing i, which I thought it should in function. But that doesn't seem to be it. I can't dupe the problem here (nor the %Cyber... file value which isn't surprising). I just jumped on here quickly, and need to do some other things, but will try to look at this later. Certainly there could be some binding issue I'm not seeing at a glance, since i is the repeat counter, but also the word being set. If I can dupe it, that will help.def:sets only fresh words or words with none value, and i had got its value from earlier use of filter when I tried dir-tree/only, then i was already set (ie. had it's "default" value) and wasn't changed, and when I run the default [g h i j k l m] [1 2 [3] 4 5 6 7] example i got its value from repeat i ... and again wasn't changed bydef. But the strange thing is that filter's foreach i and also repeat i changed the global i's value -- as classics have said *there is no scope, ahem, spoon*. set [g h i j k l m] none before trying the above example?func, which doesn't capture i. In Rebol, iterator words are captured. In Red they are not, not yet anyway. Function collects local set-word! values, and also catches the word args for [foreach remove-each repeat] (glancing at %function.reds collect-deep). Func does not do that.rule be declared local [there](https://gist.github.com/toomasv/58040ccbbfb70150dee90ba0e27b16b8#file-regex-red-L293)?to-int: func [char][to-integer char - #"0"]
./freespace refinement) was added just now.to-int function into func [numstr][to-integer numstr]. Initially it converted char, and later strings, but I forgot to correct the function. And I should clean the code from unused words, which have remaind there from some experiments, as was rule, which you pointed out.parseinto kind of FSM did the trick, as @dockimbel wrote, when introducing the brand new parse.regexon block also:>> ints: copy [] == [] >> funny: [any [collect into ints [keep integer! | skip]]] == [any [collect into ints [keep integer! | skip]]] >> parse [a 3 c 5 any words #(some: maps) [block] 357] regex "\A\k'funny'\z" == true >> ints == [357 5 3]
regex here, but still funny. For some reason regex/parse fails on this, even if it uses the same parse spec.>> _funny: ["Re" some #"d" "ish"] == ["Re" some #"d" "ish"] >> regex/parse/spec "\g'funny'" "Very Reddish indeed!" [thru [_funny] to end] == true
/i for /icase, /s for /singleline, /m for /multiline and /x for /freespace). Modes can also be specified via refinement /modes options, where options is a string of shortcoded modes. br_0), global mode refinement /global, short /g(or /modes "g") and non-capturing refinement /simplex, short /n (or /modes "n"), which turns off numbered capturing for all non-named groups). To keep track of captured strings, I added a map br_, with numbered keys (at least 0 for overall match, and numbers for each captured group + named keys for named groups). In global mode captured strings are gathered into blocks on these keys, otherwise in strings. br_0, br_1... name refer to the first match if not in the global mode, and to the last match if in global mode. In global mode captured strings can be referred as e.g. br_/1/2 for second match of the first capturing group. See examples./replace replacement refinement to it . For now replacement can be only string, which may contain backreferences to captured strings, numbered and named. Works also in global mode. Also changed br_ symbol into tcl-like & and made it changeable as eg. re-ctx/symbol: '¤, or, why not re-ctx/symbol: 'capture:). Made a repositoy for it, too: https://github.com/toomasv/regex.regex is the path to the Red side. regex leads to parse. parse leads to /refinements. /refinements leads to the joy of programming.string ~ "m/pattern/modes" for matching, string ~ "s/pattern/replace/modes" for replacing. Delimiters are up to you -- choose ones which do not occur in your pattern, eg. "m:pattern:modes". You can drop m from the beginning when matching, and modes may be empty.>> (s: "dao ke dao fei chang dao") ~ "s/dao/ming/g" head s == "ming ke ming fei chang ming"
/with refinement that takes an opts arg, and put everything in there. That can make propagating refinements a lot easier.red >> (s: "道可道非常道") ~ "s/道/名/g" head s == "名可名非常名"
source or ?? is more powerful:>> source ~ Sorry, ~ is an op! so source is not available >> ?? regex regex: unset! >> ?? re-ctx/regex *** Script Error: ?? does not allow path! for its 'value argument *** Where: ?? >> code: :re-ctx/regex
'word [word!], the type is redundant*op!?make op! :some-func seemed very simple to me??. Just a bit more logic. body-of :~system context is anonymous.." (I don't understand enough to say)print ""cheat way to return an
unset!
unset!from functions that I will run in the console so that I don't get the console output "polluted" with the return value.
unset!value.
>> f: func [] [#[unset!]] >> type? f == unset!
reflect on op! made out of function! values should be able to retrieve the body. Worth a wish ticket I think.nsource/action 'word datatypensource should be change to something that makes sense, it's just temporary dev name.nsource and my idea was to use GitHub API. Of course you can do it with git, but with the API, you have no external (call) dependency, so it's more "clean" IMO. While looking for the right API call, I found out there is new GitHub API - v4. Unlike its predecessor, v4 is based on Facebook's GraphQL, that has no support in Red.parse. Very cool Bolek.string! - I wonder how they came up with that ;)/parse string argument, so that emails, urls, tags and filenames could be parsed directly?, *, +??, *?, +??+, *+, ++/possessive (short /+) switches on possessive mode, where quantifiers ?, *, + are interpreted as possessivecomment-issue) showing how to compose the dialect. Though I will add some GitHub-specific dialect for it, GraphQL may be more powerful than REST API, but it's definitely harder to use and there's not a lot of examples.none values)type?)sourceword-browser.r, not sure where that came from tho, might be from a link Gregg postedWord-browser.r I even did not remember I made a contrib on that. Thanks ;-)/case and /tail to replace, the question is what should /tail return when used with /deep in a any-list series.any-list and return any-list at head otherwise:replace/all/deep/tail [b [a [a]] a b] 'a 'z ; [b] replace/all/deep/tail [b [a [a]] b b] 'a 'z ; [b [z [z]] b b]
/deep/tail just return head of any-series if it detects a nested any-list ??any-series, /tail is a nobrainer:replace/all/deep/tail [a a a b b] 'a 'z ; [b b]