This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; We have other reflective functions (words-of, body-of, etc.), but | |
; this is a little higher level, sounded fun to do, and may prove | |
; useful as we write more Red tools. It also shows how to make your | |
; own typesets and use them when parsing. | |
arity-of: function [ | |
"Returns the fixed-part arity of a function spec" | |
spec [any-function! block!] | |
/with refs [refinement! block!] "Count one or more refinements, and add their arity" | |
][ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Red [] | |
_5-panes-ctx: context [ | |
layout-spec: none ; layout spec we build | |
p-top: p-left: p-center: p-right: p-bottom: none ; area panels | |
def-panel-sizes: [top 50 left 200 right 150 bottom 25] | |
sizes: [] ; panel sizes used in layout | |
win-sizes: compose [ ;!! may be better to separate default |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Red [] | |
context [ | |
list: none | |
last-event: none | |
trap: function [ | |
event [word!] ;-- event name | |
input [string! binary!] ;-- input series at current loading position | |
type [datatype! word! none!] ;-- type of token or value currently processed. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; Go lang style defer experiment | |
deferreds-ctx: context [ | |
stack: [] | |
cur-stack: does [last stack] ; current function's stack | |
push-frame: does [append/only stack copy []] ; new stack frame | |
pop-frame: does [take/last stack] ; drop last stack frame | |
;push-defer: func [blk [block!]] [append/only cur-stack blk] ; LIFO | |
push-defer: func [blk [block!]] [insert/only cur-stack blk] ; FIFO | |
do-deferreds: does [foreach blk cur-stack [attempt [do blk]]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Red [] | |
e.g.: :comment | |
delta-time: function [ | |
"Return the time it takes to evaluate a block" | |
code [block! word! function!] "Code to evaluate" | |
/count ct "Eval the code this many times, rather than once" | |
][ | |
ct: any [ct 1] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Red [] | |
do %select-case.red | |
test: func [val] [print mold :val] | |
a: 15 | |
test select-case a [15 [OK]] | |
test select-case a [1 [a] 5 [b] 15 [OK]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Red [ | |
title: "Red Object Browser" | |
author: "Gregg Irwin" | |
needs: 'View | |
] | |
e.g.: :comment | |
map-ex: func [ | |
"Evaluates a function for all values in a series and returns the results." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Red [] | |
window-flags: [ | |
resize no-title no-border no-min no-max no-buttons modal popup | |
] | |
show-win-using-flags: func [flags [block!]][ | |
view/flags [backdrop sky button "OK" [unview]] flags | |
] | |
spec: [ | |
below |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Red [ | |
comment: { | |
Minimal sorted series support, allowing fast binary searches. | |
I tinkered with a "dialected" interface, and more support | |
functions, like `[remove take at index?]` but quickly saw | |
that they were of little value, and that using a parameter | |
for the command was downright misleading to read, no matter | |
how clever the implementation. `Find` is not strictly | |
necessary either, but it does make it nicely consistent |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Red [] | |
step-ctx: context [ | |
digit=: charset [#"0" - #"9"] | |
alpha=: charset [#"A" - #"Z" #"a" - #"z"] | |
alpha-num=: union alpha= digit= | |
; Could do this with charsets. | |
range-start-char?: func [val] [to logic! find "0Aa" val] |