Skip to content

Instantly share code, notes, and snippets.

>> mal/parser/run "{1 2}"
-->
match: [(error: false) any whitespace collect [ahead "("
input: "{1 2}"
match: [any whitespace collect [ahead "(" mal-list (probe
input: "{1 2}"
-->
==> matched
<--
match: [whitespace collect [ahead "(" mal-list (probe "fo
@maximvl
maximvl / info.red
Created September 4, 2017 08:50 — forked from toomasv/info.red
To get info about any function
Red []
info: func ['fn /name /intro /args /refinements /locals /return /spec
/arg-num /arg-names /arg-types /ref-names /ref-types /ref-num /type
/local intr ars refs locs ret arg ref typ
][
intr: copy "" ars: make map! copy [] refs: make map! copy [] locs: copy [] ret: copy [] typ: ref-arg: ref-arg-type: none
if lit-word? fn [fn: to-word fn]
unless find [op! native! function! action!] type?/word get fn [
cause-error 'user 'message ["Only function types accepted!"]
]
Red [
author: { Maxim Velesyuk }
description: {
colors palette showcase
}
]
sys-words: words-of system/words
colors: copy []
forall sys-words [
@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 [
description: {
Attempt to copy Haiku Editor
http://forthsalon.appspot.com/haiku-editor
}
todo: {
* Optimize GUI
* Add memory and words: @ !
* Add return stack and words: push pop r@
* Add mouse handling: mx my button buttons
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).
@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