g, yog someday @gltewalt.jpegg thoughsave/as with none works correctly either /as => Specify the format of data; use NONE to save as plain text.save/as/as then, but it can make things easier sometimes. Propagating refinements can lead to more complex code. By having a refinement that lets you *optionally* include an arg (effectively), any wrappers can just always use /as.if word? format check can go away./all is TBDeither as [as word? format]load/as but it returns none if the codec isn’t supported. And load/as %my-file none worksall as in the standard function, which is a good catch, as it would need to be system/words/all due to the refinement of the same name.makedoc2.remit: func [data /line] [ ; Primary emit function: insert insert tail out reduce data newline ]
/line for? It isn't used in this func blockscript: object [ code: 300 type: "Script Error" wat: ["wat?"] no-value: [:arg1 "has no value"] need-value: [:arg1 "needs a value"]
/blockchain, asking about crypto but having absolutely zero interest in language itself?Docathon!](https://github.com/JuliaLang/julia/projects/8) github project which IMO we should adopt sooner or laterif true [print "Vive Red !"]
emoji: :function,.([:<@:|.1{.~])"0>:i.5
┌─────────┐
│1 │
├─────────┤
│0 1 │
├─────────┤
│0 0 1 │
├─────────┤
│0 0 0 1 │
├─────────┤
│0 0 0 0 1│
└─────────┘calland kill it when not responding.priority.listings even though it doesn't support Red, as this package doesn't require extra installations. Maybe someone in the future adds Red to its supported languages.key-log: copy []
log-key: func [key dir][repend key-log [now/precise key dir]]
view [
area hint "What are your thoughts?"
on-key-down [log-key event/key 'dn]
on-key-up [log-key event/key 'up]
button "Show Log" [print mold new-line/skip key-log on 3]
]load all Red data, including nested blocks and objects, cool! How hard was that? Now all you have to do is implement all the datatypes to handle their actions, and natives. From their it's as easy as any other interpreter for a multi-paradigm language that uses definitional scoping. ;^)>> system/console/history: "" == "" >> "hi" == "hi" >> system/console/history == "^G^@^@^@^@^@^@^@ð1^M^B^@^@^@^@^G^@^@^@^@^@^@^@Ø1^M^B^@^@^@^@" >> clear system/console/history == "" >> type? system/console/history == string!
unless sub? [stack/set-last stack/top]unless sub? [stack/set-last stack/top] fixes all the examples I could find in 3156, 3128, and your closed 3098.either sub? [stack/push parent][stack/set-last parent] in the code?call and never had it not work that I noticedunless. 56 ok - not-compile......................................1 / 1. do %run-all.r from R2?./r2 directory and because of that all test failscall issue was something I stumbled onto, and Qxtie just made a change. I never made a ticketn=: 5 (!2*n)%(!n)*(!n+1) 42 (!2*n)%(n*&:!n+1) 42 (!2*n)%([*&:!+&1)n 42 (([:!2&*)%[*&:!+&1)n 42 (!@:(2&*)%[*&:!+&1)n 42 (!@+:%[*&:!+&1)n 42 (!@+:%[*&!>:)n 42 (!@+:%[*&!>:)i.10 1 1 2 5 14 42 132 429 1430 4862
red tag on SO questions?to float! "". It does get fired with a string of length 1 or greater.none! or I forgot... hmmmto float! "" issue is a regression. Haven't dug in to look at the causal source though.+/(#~(2 3$1 0)-:"2[:="1([:+/i.([#~0=|)])^:(<3))"0 i.1e4
red/sandbox is gentlemans club after all[by messages] [by characters]do not work now, but that's not such big problem as @9214 taking first place ;)J and ends in avaScript. And involves manipulating data so @9214 is accidentally filtered out.= when I jump back over to Red>> =: make op! func [this that][set this that] == make op! [[this that]] >> 'x = 1 == 1 >> x == 1
- (return_type)instanceMethod2With2Parameters:(param1_type)param1_varName param2_callName:(param2_type)param2_varName;
return_type instanceMethod2With2Parameters (param1_type param1_varName, param2_type param2_varName=default);
param2_callName?crazy distributed database appear, easy doesn't come to my mind when playing word association. range from web):reduce-in-place funcs? Not sure how useful it is but here is one thought:reduce-in-place: func [block [block!] /local pos][
while [not empty? block][
block: change/part block do/next block 'pos pos
] head block
]
>> reduce-in-place b: [does [print "hi"] f: func [a][a + 2] "probe [me]" f 1 b/2 3]
== [func [][print "hi"] func [a][a + 2] "probe [me]" 3 5]
>> b/1
hi
>> :b/1
== func [][print "hi"]
>> :b/2
== func [a][a + 2]
>> do b/3
[me]
== [me]/deep:reduce-in-place: func [block [block!] /deep /local pos][ while [not empty? block][ block: either all [deep block? block/1][ change/only block reduce-in-place/deep block/1 ][ change/part block do/next block 'pos pos ] ] head block ] >> reduce-in-place/deep b: [does [print "hi"] [func [a][a + 1] [b/2/1 7]]] == [func [][print "hi"] [func [a][a + 1] [8]]]
block: either all [deep block? :block/1][ though. Then this works too:>> reduce-in-place/deep b: [does [print "hi"] [func [a][a + 1] 3 [b/2/1 7]]] == [func [][print "hi"] [func [a][a + 1] 3 [8]]] >> reduce-in-place/deep b hi == [unset [4 [8]]]
reassess is good too.inc: func ['val][set val (get val) + 1] dec: func ['val][set val (get val) - 1] incr: func ['val step][set val (get val) + step] decr: func ['val step][set val (get val) - step] ++: make op! :incr --: make op! :decr increment: func ['val /by step][set val (get val) + any [step 1]] decrement: func ['val /by step][set val (get val) - any [step 1]] >> e: 0 == 0 >> inc e == 1 >> incr e 5 == 6 >> decrement e == 5 >> increment/by e 22 == 27 >> e ++ 3 == 30 >> e -- 28 == 2 >> e == 2 >> e: 1-May-2018 loop 5 [print also e inc e] 1-May-2018 2-May-2018 3-May-2018 4-May-2018 5-May-2018 >> e: #"a" loop 26 [prin also e inc e] abcdefghijklmnopqrstuvwxyz
op!system/lexer/pre-load: func [source part /local int i1 i2 i3 blk len][ int: charset [#"0" - #"9"] parse source [ some [ ahead [some int ".."] s: [copy i1 some int ".." copy i2 some int (i3: 1) opt [#"|" copy i3 some int]] e: ( i1: to-integer i1 i2: to-integer i2 i3: to-integer i3 blk: make block! len: i2 - i1 / i3 + 1 change/part s repeat i len [mold append/only blk i1 + (i - 1 * i3)] e ) | skip ] ] ] >> foreach i 0..10|2 [print i] 0 2 4 6 8 10 >> reduce [5..9 4..8|2 reverse 3..15|3] == [[5 6 7 8 9] [4 6 8] [15 12 9 6 3]]
int: charset [#"-" #"0" - #"9"]
mold repeat i len [append/only
>> -1..5 == [-1 0 1 2 3 4 5] >> -1..5|2 == [-1 1 3 5] >> 10..5|-2 == [10 8 6]
try: does [foreach i a..b|c [print i]] >> a: 5 b: 15 c: 3 try 5 8 11 14 >> a: 15 b: 5 c: -3 try 15 12 9 6
intupelate) one of my big issues with the value of literal ranges. They are literal. We do use those, but they're not nearly as useful as parameterized ranges.system/console/eval-command "1">> system/console/eval-command "1" *** Script Error: set does not allow error! for its word argument *** Where: set *** Stack: load == 1 == 1 == 1 == 1 == 1 == 1 == 1 == 1 == 1 == 1 == 1 == 1 == 1 == 1 == 1 == 1 == 1 == ""
>> system/console/eval-command "1" *** Internal Error: stack overflow *** Internal Error: stack overflow *** Where: set *** Stack: == 1 == 1 == 1 == 1 == 1 == 1 == 1 == 1 == 1 == 1 == 1 == 1 == 1 == 1 == 1 == 1 == "" >> *** Script Error: value out of range: 37 *** Where: poke *** Stack: ask do-events do-actor do-safe
linux: 304
win: 57
macos: 178
rpi: 108remove find idiom is common enough that delete could be implemented for series values to do that. Delete is informally categorized as an I/O action, but what do others think about that?delete is taken already, I implemented expunge :-)expunge: func [face /from pane][pane: any [pane face/parent/pane] remove find pane face]
delete, because of the arity. Unless we add something like a /part refinement.remove and add the refinement there.delete for face-deleting also -- less to remember.. Want to delete something? -- delete memorize: function [arg1 arg2 /recall n][
history: []
if recall [return new-line/all/skip case [
n = 'all [history]
n = 'last [at history (length? history) - 1]
block? n [copy/part at history 2 * n/1 - 1 2 * n/2]
integer? n [copy/part at history 2 * n - 1 2]
] true 2]
append append history arg1 arg2
[do something with args]
]
memorize 1 2
;== [do something with args]
memorize 3 4
;== [do something with args]
memorize 5 6
;== [do something with args]
memorize 'a 'b
;== [do something with args]
memorize/recall none none 'all
;== [
; 1 2
; 3 4
; 5 6
; a b
;]
memorize/recall none none 'last
;== [
; a b
;]
memorize/recall none none 2
;== [
; 3 4
;]
memorize/recall none none [2 2]
;== [
; 3 4
; 5 6
;]memoize should accept a function and return its memoized version.factorial: function [n][
values: [1.0]
either val: pick values n + 1 [val][
while [
n + 2 > l: length? values
][
append values l * val: last values
]
]
val
]memorize: function [/opt arg1 arg2 /recall n][/recallfactorial3: function [n][
values: #(1 1.0)
either val: values/(n + 1) [val][
while [
n + 2 > l: length? values
][
values/(l + 1): l * val: values/:l
]
]
val
]make hash! was plain stupid as it makes new one on each run :flushed:factorial3 171memoize to take a list of args to act on. e.g. /with, where the default is to memoize all args.select/only/skip ... 2, where keys are reduced argument lists and values are associated results, previously returned from a function. /only refinement to to-block?to-block: func ["Convert to block! value" value /only][
either only [append/only copy [] :value][to block! :value]
]
to-block "c"
;== [c]
to-block/only "c"
;== ["c"]
to-block [c]
;== [c]
to-block/only [c]
;== [[c]]To- functions are automatically generated, so it's not as easy as just changing that one func. to-* should be idempotent if the arg is already the target type (ignoring copying), where your last example would create deeper and deeper nestings with /only.remove-from-map by values, by keys, by datatypes. Will show soon. The question above was a by-product, not vital. Thanks for explanation!remove-from-map: function [map vals /keys /local skp1 skp2][
unless block? vals [vals: append copy [] vals]
set [skp1 skp2] either keys [[0 -2]][[1 -3]]
block: skip body-of map skp1
forall vals [
while [
block: find/skip/tail block vals/1 2
][
put map first skip block skp2 none
]
block: skip body-of map skp1
]
map
]
>> remove-from-map #(a 1 b 2 c "c" d g "e" :f 1 10) "c"
== #(
a: 1
b: 2
d: g
"e" :f
1 10
)
>> remove-from-map #(a 1 b 2 c "c" d g "e" :f 1 10) get-word!
== #(
a: 1
b: 2
c: "c"
d: g
1 10
)
>> remove-from-map #(a 1 b 2 c "c" d g "e" :f 1 10) [1 10]
== #(
b: 2
c: "c"
d: g
"e" :f
)
>> remove-from-map #(a 1 b 2 c "c" d g "e" :f 1 10) reduce [string! get-word!]
== #(
a: 1
b: 2
d: g
1 10
)
>> remove-from-map/keys #(a 1 b 2 c "c" d g "e" :f 1 10) set-word!
== #(
"e" :f
1 10
)
>> remove-from-map/keys #(a 1 b 2 c "c" d g "e" :f 1 10) [1 "e"]
== #(
a: 1
b: 2
c: "c"
d: g
)
>> remove-from-map/keys #(a 1 b 2 c "c" d g "e" :f 1 10) reduce [string! integer!]
== #(
a: 1
b: 2
c: "c"
d: g
)within? works correctly. E.g. following pic is from the code>> view/no-wait [box 101x101 draw [b1: box 0x0 100x100 pen red b2: box 0x0 10x10 b3: box 90x90 100x100]]
== make object! [
type: 'window
offset: 902x505
size: 130x121
== make object! [
type: 'window
offset: 902x505
size: 130x121
te...
>>
>> within? b2/3 b1/2 b1/3
== true
>> within? b3/3 b1/2 b1/3 - b1/2
== false
>> within? b3/3 - 1 b1/2 b1/3 - b1/2
== truewithin? is currently defined aswithin?: func [
{Return TRUE if the point is within the rectangle bounds}
point [pair!] "XY position"
offset [pair!] "Offset of area"
size [pair!] "Size of area"
return: [logic!]
][
to logic! all [
point/x >= offset/x
point/y >= offset/y
point/x < (offset/x + size/x)
point/y < (offset/y + size/y)
]
]< in last two comparisons, instead of <=.b1/3 - b1/2. Let's have a small box that starts at 1x1 and goes to 2x2. If I compute size as you do, I will get that the size is 1x1. That's obviously wrong.end - start + 1?end from start and size, which I would intuitively do as start + size, should instead be calculated as start + size - 1?1x1 - 2x2 example. If you count it as end - start, you get 1x1 size and if you count it as start + size, you'll get 3x3 as end.box 0x0 100x100 face shoud be one px bigger, e.g. in view [box 101x101 draw [box 0x0 100x100]], for box's size is 101x101. Got it. Thanks :)dir-tree: function [][p: :parse a: :append c: :copy o: c {} pr: c [] d: :read e: :either m: :remove h: :change-dir
p p d %. r: [collect some [s: keep file! [if (dir? s/1) keep (h s/1 p d %. r) (cd ..) |]]]
r: [some [s: file! (a o a e dir? s/1 [also a c pr s/1 a pr #"^-"][a c pr s/1] #"^/") | block! (p s/1 r) (m pr)]] o]backward-rule: [collect some [l: keep word! to end | [pair! | integer! | end] (l: back l) :l]] parse tail [box 1x1 2x2 10] backward-rule ;=[box] parse skip [line 1x1 2x2 10x20 1000x600] 4 backward-rule ;=[line]
parse tail [line 1x1 2x2 10x20 1000x600] [some [l: 'line to end | [pair! | integer! | end] (l: back l) :l]] ;== true parse tail [box 1x1 2x2 10x20 1000x600] [some [l: 'line to end | [pair! | integer! | end] (l: back l) :l]] ;== false
view [ box snow 300x300 draw [ fill-pen 0.0.0.254 box 50x50 250x250 fill-pen 0.0.0.254 box 100x100 200x200 ] on-down [ set [series failing ending] reduce either event/ctrl? [ [tail face/draw [(l/-1: 0.0.0.254 l: back l) :l] [if (head? l) to end | (l: back l) :l]] ][ [face/draw [(l/-1: 0.0.0.254)] [skip]] ] parse series [ some [ l: 'box set s pair! set e pair! [ if (within? event/offset s sz: e - s + 1)( ofs: event/offset - s l/-1: 'red ) break | failing ] | ending ] ] ] all-over on-over [ if event/down? [ l/2: event/offset - ofs l/3: l/2 + sz ] ] ]
ws: charset reduce [space newline tab]
rule: [
remove thru {<div class='blog-posts hfeed'>}
some [
remove [{<div class='blog-pager' id='blog-pager'>} thru end]
|
remove [
"<script" thru "script>"
| "<style" thru "style>"
| #"<" thru #">"
]
| change " " #" "
| change "&" #"&"
| change ["" s: to [e: #";"]] (to-char to-integer copy/part s e)
| skip
]
]
view/flags [
on-resizing [
foreach-face face [
either face/type = 'field [
face/size/x: event/window/size/x - 20
][
face/size: event/window/size - face/offset - 10x10
]
]
]
below
field 400 default https://www.red-lang.org focus on-enter [
parse tx: read face/data rule
parse tx [some [2 newline change [newline some ws] newline | skip]]
ar/text: tx
]
ar: area 400x400 wrap
] 'resizeRed [Needs: View]
ws: charset reduce [space newline tab]
rule: [
;remove thru {<div class='blog-posts hfeed'>}
some [
; remove [{<div class='blog-pager' id='blog-pager'>} thru end]
;|
remove [
"<script" thru "script>"
| "<style" thru "style>"
| #"<" thru #">"
]
| change " " #" "
| change "&" #"&"
| change ["" s: to [e: #";"]] (to-char to-integer copy/part s e)
| skip
]
]
view/flags [
on-resizing [
foreach-face face [
either face/type = 'field [
face/size/x: event/window/size/x - 20
][
face/size: event/window/size - face/offset - 10x10
]
]
]
below
field 400 default http://www.rebol.com focus on-enter [
parse tx: read face/data rule
parse tx [some [2 newline change [newline some ws] newline | skip]]
ar/text: tx
]
ar: area 400x400 wrap
] 'resizeDivining Rod?'quoted arguments well, raises a couple of design questions (order of refinements in function call, treating series arguments with same? comparator), but overall seems quite robust (although I haven't check anything much).inspect: func [function][
probe new-line/skip
get in context? first select body-of :function 'any 'memory
on 2
]
factorial: memoize func [n][
if n <= 1 [return n]
n * factorial n - 1
]>> factorial 10
3628800
== 3628800
>> inspect :factorial
[
[1] 1
[2] 2
[3] 6
[4] 24
[5] 120
[6] 720
[7] 5040
[8] 40320
[9] 362880
[10] 3628800
]