Skip to content

Instantly share code, notes, and snippets.

@TimeSeriesLord
TimeSeriesLord / dyn-rule.red
Created September 28, 2016 03:48 — forked from dockimbel/dyn-rule.red
Example of dynamic rule creation in Parse dialect using the Red language. The code can be copy/pasted directly into a Red console.
Red [
Author: "Nenad Rakocevic"
Date: 06/12/2013
Note: {
This short Red program demonstrates the use of dynamically built Parse rules.
It parses an imaginary external DSL with variables, and detects if a variable has
been used before been properly declared and initialized.
The detection works by comparing found variables against a list of declared
variables. The list starts empty, and it grows as new variables are collected.
@TimeSeriesLord
TimeSeriesLord / lc.r
Created September 28, 2016 03:50 — forked from dockimbel/lc.r
List comprehension dialect for Rebol
REBOL []
print []
lc: function [block] [lc-state lc-rule input-rule filter-rule i e] [
lc-state: make object! [
do-block: copy []
inputs: copy []
filter-block: none
input-state: copy []
res: copy []
]
@TimeSeriesLord
TimeSeriesLord / analog-clock.red
Created September 28, 2016 03:52 — forked from greggirwin/analog-clock.red
An analog clock for Red
Red [
Title: "Red O'clock"
Author: "Gregg Irwin"
]
degree-to-xy: func [rad "radius" deg "degrees"] [
as-pair (rad * sine deg) (rad * negate cosine deg)
]
sex-to-degree: func ["Sexagesimal to degrees" n] [n * 6]
Red [
Needs: 'View
]
R: G: B: box: value: none
to-color: function [r g b][
color: 0.0.0
if r [color/1: to integer! 256 * r]
if g [color/2: to integer! 256 * g]
@TimeSeriesLord
TimeSeriesLord / greggs-mezz.red
Created September 28, 2016 03:56 — forked from greggirwin/greggs-mezz.red
A bunch of general purpose mezzanine funcs for Red.
Red [
File: %greggs-mezz.red
Author: "Gregg Irwin"
Purpose: "An interim mezzanine dump, while Red is still moving fast."
Tabs: 4
Comment: {
Not everything here has been well-tested or, well, tested. Most
of the functions are ports from R2, with many more to come. I'm
combining everything in one file for ease of experimentation, so
you don't have to worry about includes or dependencies with the
@TimeSeriesLord
TimeSeriesLord / math-lab.red
Created September 28, 2016 03:57 — forked from greggirwin/math-lab.red
Interactive math function laboratory
Red [
Title: "math-lab.red"
Author: "Gregg Irwin"
File: %math-lab.red
Needs: 'View
Purpose: {
Experiment, to see what an interactive "Lab" tool might look
like, for general language functions. i.e., take the idea of
font-lab, effect-lab, gradient-lab, etc., and apply it to
functions to aid in language discovery and learning.
@TimeSeriesLord
TimeSeriesLord / trig-lab.red
Created September 28, 2016 03:57 — forked from greggirwin/trig-lab.red
Interactive trig function laboratory
Red [
Title: "trig-lab.red"
Author: "Gregg Irwin"
File: %trig-lab.red
Needs: 'View
Purpose: {
See %math-lab comments for details. This script focuses
on trigonometric functions.
}
]
@TimeSeriesLord
TimeSeriesLord / menu.red
Created September 28, 2016 03:57 — forked from greggirwin/menu.red
Basic Red menu demo
Red [
File: %menu.red
Author: "Gregg Irwin"
]
; The menu dialect in Red is easy. When making a face, you use `menu:`
; followed by a block of [string! block!] pairs, where the string is the
; text of the top level menu and the block is a simple dialect that
; defines the drop-down menu items. Each item can be either a string!
; followed by a word!, or the special separator marker of '---. That's it.
@TimeSeriesLord
TimeSeriesLord / invalid-utf8.red
Created September 28, 2016 04:01 — forked from greggirwin/invalid-utf8.red
Red invalid-utf8? function
invalid-utf?: function [
; https://robots.thoughtbot.com/fight-back-utf-8-invalid-byte-sequences
"Checks UTF encoding; if correct, returns none else position of error."
binary [binary!]
][
bad: [
#{C0} | #{C1} | #{F5} | #{F6} | #{F7} | #{F8} | #{F9} | #{FA}
| #{FB} | #{FC} | #{FD} | #{FE} | #{FF}
]
if parse binary [any [[mark: bad (return mark)] | skip]] [none]
@TimeSeriesLord
TimeSeriesLord / entab-detab.red
Created September 28, 2016 04:03 — forked from greggirwin/entab-detab.red
Red ENTAB/DETAB mezzanines
Red []
; Steeve gets credit for this one
detab: function [
"Converts leading tabs in a string to spaces. (tab size 4)"
string [any-string!] "(modified)"
/size
sz [integer!] "Number of spaces per tab"
/all "Change all, not just leading"
][