Skip to content

Instantly share code, notes, and snippets.

@maximvl
maximvl / state.red
Created July 22, 2017 23:28
Red parse + states example
Red []
parser: context [
state: []
rules: [
any [
number! (append state 'number) |
word! (append state 'word) |
time! (append state 'time)
]
@maximvl
maximvl / html-parser.red
Created July 22, 2017 10:16
toy html parser
Red []
{
grammar HTML
document <- (doctype / text / tag)*
tag <- open_tag (text / tag)* close_tag
open_tag <- "<" [0-9a-zA-Z \"'=-]+ ">"
close_tag <- "</" [0-9a-zA-Z]+ ">"
doctype <- "<!DOCTYPE " [0-9a-zA-Z]+ ">"
text <- [^<]+
}
@maximvl
maximvl / qf.red
Created May 15, 2017 21:51
quick funcs
Red [
author: {Maxim Velesyuk}
description: {
Quick in-place function definitions without explicit arguments specification.
`_` is next arugment, `_N` is N-th argument
}
]
inc: func ['word] [set word 1 + get word]
Red [
author: {Maxim Velesyuk}
description: {draw dialect playground}
]
demo: trim {
fill-pen gray
box 0x0 400x400
do [c: to-tuple reduce [
random 255 random 255 random 255]
* (defun f (x y) (/ x y))
WARNING: redefining COMMON-LISP-USER::F in DEFUN
F
* (f 5 0)
debugger invoked on a DIVISION-BY-ZERO in thread
#<THREAD "main thread" RUNNING {100399C493}>:
arithmetic error DIVISION-BY-ZERO signalled
Operation was /, operands (5 0).
Red [
description: {simple game}
author: {Maxim Velesyuk}
version: 2.2
changelog: {
2.2
* added sleep to the loop to reduce CPU load
2.1
* added win screen display time
@maximvl
maximvl / poor-mans-scopes.red
Last active August 14, 2019 12:30
Dynamic variables in Red
Red [
author: "Maxim Velesyuk"
description: "Dynamic variables implementation for Red"
]
; utils
forskip: func ['series skipn body /local s] [
s: get series
while [ not tail? s ] [
do body
@maximvl
maximvl / restarts.red
Last active August 14, 2019 12:30
CL condition-restarts in Red
Red [
author: "Maxim Velesyuk"
description: "Common Lisp condition-restart system implementation for Red"
]
; utils
*word-counter*: 0
gen-word: does [
*word-counter*: *word-counter* + 1
to-word append "G-" to-string *word-counter*
@maximvl
maximvl / datatype-help.red
Created March 26, 2017 13:35 — forked from greggirwin/datatype-help.red
Small GUI experiment for showing datatype information.
Red []
form-all: func [blk][
forall blk [blk/1: form blk/1]
blk
]
types-of: function [value [typeset!]][
; typesets don't support reflection
third load mold value