Skip to content

Instantly share code, notes, and snippets.

View benchhash.red
Red []
clock: func [code /local t1 t2] [
t1: now/precise/time
loop 100 code
t2: now/precise/time
print [(t2 - t1) mold/flat code]
]
m1: make hash! []
View benchmap.red
Red []
clock: func [code /local t1 t2] [
t1: now/precise/time
loop 100 code
t2: now/precise/time
print [(t2 - t1) mold/flat code]
]
m1: #()
View benchhash2.red
Red []
clock: func [code /local t1 t2] [
t1: now/precise/time
loop 100 code
t2: now/precise/time
print [(t2 - t1) mold/flat code]
]
m1: make hash! []
View dot-chaining.red
Red []
; WOW! chain expressions with a dot to make them more readable!
; an inline transformation of a chain of function applications into a lisp-like pyramid of braces ;)
; (expr) . func args... => (func (expr) args...)
; e.g. [1 2 3 4 5] . skip 1 . change/part '- 3 . head => (head (change/part (skip ([1 2 3 4 5]) 1) '- 3))
#macro [skip '. [word! | path!]] func [[manual] s e /local a r p p2] [
p: s/3
a: either word? p [
@hiiamboris
hiiamboris / composite.red
Last active Jun 12, 2018 — forked from greggirwin/composite.red
Composite func (compose for strings) for Red
View composite.red
Red [
Author: [@greggirwin @endo @toomasv]
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
}
]
@hiiamboris
hiiamboris / glob-test.red
Last active Jun 17, 2018
list files recursively, with a pattern
View glob-test.red
Red [title: "glob func test script"]
#include %glob.red
unless value? 'input [input: none]
root: %globtest-temp-dir.$$$
if exists? root [print ["please remove the" root "from" what-dir "first"] input quit]
change-dir make-dir root
@hiiamboris
hiiamboris / parse-then-test.red
Created Jul 21, 2018
Test of the `then` keyword
View parse-then-test.red
Red []
idiom: [ [a (x: b) | reset (x: c)] x | reset d ] ; 1
impl: [ a then b | reset c | reset d ] ; 2
;impl: [ a b | reset c | reset d ] ; 2
;impl: [ (f: yes) a (f: no) b | reset if (f) c | reset d ] ; 1
;impl: [ a b | reset not a c | reset d ] ; 3
;impl: [ not a c | reset a b | reset d ] ; 3
;impl: [ [a fail b] | reset c | reset d ] ; 2, nightly build only
;impl: [ p: a [b | :p reset d |] | reset c | reset d ] ; 1
@hiiamboris
hiiamboris / inspect.red
Created Dec 11, 2018
image inspector func
View inspect.red
Red []
inspect: function [i] [
pixel: 10x10
? (also i': make image! i/size * pixel
x: y: repeat y i/size/y [
repeat x i/size/x [
p: as-pair x y
draw i' compose [
line-width 1 pen (i/:p) fill-pen (i/:p)
@hiiamboris
hiiamboris / benchcollect.red
Created May 19, 2018
A `collect` mezzanine variant of improved performance and RAM footprint
View benchcollect.red
Red []
; outright improvement of collect mezzanine's performance and RAM footprint
; the compiled default "collect"
collect1: :collect
; the interpreted default "collect"
collect2: func spec-of :collect body-of :collect
View piping.red
Red []
; WOW! dialectic version of function piping!
; . with a cutest dot!
; . to make expressions more readable!
; . can be invoked recursively (pipe [ pipe [...] . ... ])
; e.g. [1 2 3 4 5] . skip 1 . change/part '- 3 . head
; => head change/part skip [1 2 3 4 5] 1 '- 3