Skip to content

Instantly share code, notes, and snippets.

View greggirwin's full-sized avatar

Gregg Irwin greggirwin

  • Redlake Technologies
View GitHub Profile
@greggirwin
greggirwin / help.red
Last active April 10, 2017 14:02
Help related functions for Red
Red [
Title: "Red help functions"
Author: "Gregg Irwin"
File: %help.red
Tabs: 4
Rights: "Copyright (C) 2013-2017 All Mankind. All rights reserved."
License: {
Distributed under the Boost Software License, Version 1.0.
See https://github.com/dockimbel/Red/blob/master/BSL-License.txt
}
@greggirwin
greggirwin / poor-mans-scopes.red
Last active April 6, 2017 18:03 — forked from maximvl/poor-mans-scopes.red
Dynamic variables in Red
Red [
author: ["Maxim Velesyuk" "Gregg Irwin"]
description: "Dynamic variables implementation for Red"
notes: {
http://www.gigamonkeys.com/book/variables.html
TBD: Better names.
}
]
@greggirwin
greggirwin / composite.red
Created April 17, 2017 16:55
Red COMPOSE for strings
Red [
Author: "Gregg Irwin"
Purpose: "COMPOSE for strings"
Notes: {
TBD: Security model for eval'ing expressions
}
]
; The name of the function (`composite`) is tricky. Rebol calls this
; `build-markup`, which isn't bad, but defines a more limited view of its
@greggirwin
greggirwin / 99-bottles-1.red
Created April 24, 2017 19:33
99 Bottles of Beer
bottles: func [n][
switch/default n [
0 ["no more bottles"]
1 ["1 bottle"]
][form reduce [n "bottles"]]
]
verse: func [n][
either n = 0 [
{No more bottles of beer on the wall, no more bottles of beer.
@greggirwin
greggirwin / sing-drinking-song.red
Created April 24, 2017 19:39
When you don't want 99 bottles of beer
sing: function [input][
input: copy input
n: orig-num: first input
sing-verse: func [n][
print [
n =phrase "on the wall," n =phrase ".^/"
"Take one down and pass it around,"
either n > 1 [n - 1]["no more"] =phrase "on the wall.^/"
]
]
@greggirwin
greggirwin / def-and-dupe.red
Created May 4, 2017 15:42
Default and Dupe Demo
Red []
e.g.: :comment
; Using a context here, because Red's compiler doesn't like inner funcs yet.
defaulting-ctx: context [
def: func [w "Word" v "Value"][
; We're setting one word, so don't need to use set/only.
if any [not value? :w none? get w][set w :v]
get w
@greggirwin
greggirwin / datatype-doc-strings.red
Created May 16, 2017 23:37
Doc strings for datatypes, maybe to add to `help`
datatype-doc-strings: [
action! "Polymorphic native datatype function"
binary! "Series of byte values"
bitset! "Set of bit flags, used with parse as charsets"
block! "Series of heterogeneous values"
char! "Single unicode character"
datatype! "Value category, determines form and behavior"
date! "Combined date, time, and timezone"
decimal! "Accurate decimal value, no floating point error"
email! "Email address"
@greggirwin
greggirwin / nsource.red
Last active June 13, 2017 05:27 — forked from rebolek/nsource.red
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 / configurable-tile-game.red
Created July 10, 2017 16:56
Configurable Tile Game
Red [
Purpose: "Simple tile game where you can set the the board and button size."
Author: "Gregg Irwin"
Notes: {
Based on https://github.com/red/code/blob/master/Showcase/tile-game.red
Shows how to dynamically generate a VID GUI, including static elements.
}
]
@greggirwin
greggirwin / drop-down-demo.red
Last active July 22, 2017 10:58
VID drop-down style demo
Red [
title: "Drop-down demo"
author: "Gregg Irwin"
]
; The data facet accepts arbitrary values, but only string values will be added
; to the list and displayed. Extra, non-string values can be used to create
; associative arrays, using strings as keys. The `selected` facet is a 1-based
; integer index, indicating the position of the selected string in the list,
; not in the `data` facet.