Skip to content

Instantly share code, notes, and snippets.

; proof of concept (but usable!) implementation of immutable persistent 'blocks' in Red
; author: Jay G. Porcasi (@numberjay)
; the exported API is at the bottom, starting with: set '<function name> ...
; free to use without any warranty of any kind: use at your own leisure and risk
; for bugs, suggestions, questions... comment here below or reach me on Gitter (@numberjay)
; copyright Jay G. Porcasi 2017
context [
; all functions ending with ' are helper functions working on 'immutable' blocks only
@greggirwin
greggirwin / requesters.red
Last active February 6, 2020 21:41
Red requesters (alert, confirm, prompt, etc.)
Red [
author: ["Gregg Irwin"]
notes: {
Experimental requesters, for design discussion. Not just about the
implementation, but about modal vs modeless dialogs. I think there's
value in the simple, modal approach, but we probably want to provide
more advanced options. e.g. document/sheet modal, and mobile standard
approaches.
TBD: Determine if we want to build everything on inner funcs that are
@greggirwin
greggirwin / composite.red
Last active May 16, 2019 17:14
Composite func (compose for strings) for Red
Red [
Author: [@greggirwin @endo @toomasv @hiiamboris]
Purpose: "COMPOSE for strings"
Notes: {
TBD: Security model for eval'ing expressions
TBD: Decide if support for custom marker and eval contexts are worthwhile
TBD: Finalize refinement names
TBD: Decide if suport for function contexts is worthwhile
TBD: Make it a macro?
TBD: Decide if file and url params should be read automatically
@greggirwin
greggirwin / profile.red
Last active December 28, 2020 06:17
Basic profiling for Red code comparisons
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]
@greggirwin
greggirwin / compare-times.red
Last active October 28, 2017 22:23
compare-times perf test idea for Red
; Stats added by @toomasv
compare-times: func [
blocks "Block of code blocks to performance compare"
/count ct
/local t n baseline res blk stats1 memory time code template
][
ct: any [ct 1]
t: now/time/precise
loop ct [do []]
baseline: now/time/precise - t
@greggirwin
greggirwin / red-object-browser.red
Last active October 16, 2020 17:48
Red Object Browser
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."
@rebolek
rebolek / nsource.red
Last active June 19, 2019 20:11
Provides source of Red native functions
Red [
Title: "Nsource - native source"
Purpose: "Print source for native functions"
Author: "Boleslav Březovský"
Date: "8-6-2017"
]
indent: func [
"(Un)indent text by tab"
string [string!] "Text to (un)indent"
@greggirwin
greggirwin / red-paint-with-time-travel.red
Last active February 8, 2018 18:29
Red Paint with time travel
Red [
title: "Paint"
Author: [REBOL version "Frank Sievertsen" Red port "Gregg Irwin"]
File: %paint-with-time-travel.red
Tabs: 4
Needs: View
version: 0.0.3
Notes: {
The original didn't have time travel.
@greggirwin
greggirwin / collect-values.red
Last active February 11, 2018 04:59
Red collect-values and collect-words functions
collect-values: function [
"Collect values in a block, by type or custom parse rule"
block [block!]
rule "Datatype, prototype value, or parse rule"
/deep "Include nested blocks"
/local v
][
rule: switch/default type?/word rule [
datatype! [reduce [rule]] ; Turn a plain datatype into a parse rule for that type.
block! typeset! [:rule] ; Blocks and typesets (e.g. any-word!) work directly as rules.
Red [] L: charset "ABCDEFGHI" D: union N: charset "123456789" charset "0"
repeat y 9 [repeat x 9 [col: either x = 1 [#"^(2028)"][#"A" + (x - 2)]
append p: [] set ref: (to word! rejoin [col y - 1]) make face! [size: 90x24
type: pick [text field] header?: (y = 1) or (x = 1)
offset: -20x10 + as-pair ((x - 1) * size/x + 2) ((y - 1) * size/y + 1)
text: form case [y = 1 [col] x = 1 [y - 1] 'else [copy ""]]
para: make para! [align: pick [center right] header?]
extra: object [name: form ref formula: old: none]
actors: context [on-create: on-unfocus: function [f e][f/color: none
if rel: f/extra/old [react/unlink rel 'all]