Skip to content

Instantly share code, notes, and snippets.

@hiiamboris
hiiamboris / prealloc-lab.red
Last active December 12, 2024 09:08
preallocation efficacity study
Red [
title: "Preallocation lab"
author: @hiiamboris
license: MIT
]
sizes: repeat n 11 [append [] 2 ** (9 + n)] ;-- 1K .. 1M
gc-color: coal
strategies: #[
@hiiamboris
hiiamboris / parse-into-tree.red
Created July 11, 2024 13:39
Automatic tree construction during parsing (a dusty experiment)
Red []
context [
keywords: make hash! [
case quote skip none end opt not ahead any some while to thru if
into fail break reject set copy collect keep remove insert change
]
log: []
last-push: []
tracer: function [event [word!] match? [logic!] rule [block!] input [series!] stack [block!] /local name /extern last-push] [
@hiiamboris
hiiamboris / protect.red
Last active November 30, 2023 21:04
An experiment in ad-hoc protection
Red [title: "an experiment with adhoc protection"]
;; problem is that once it's assigned to a deep-reactor, protection is lost
;; and we can only protect series, not maps or objects like this (limitation of ownership system)
;; REQUIRES https://codeberg.org/hiiamboris/red-common
#include %common/tree-hopping.red
guard: object [
own: func [s [series!]] [modify s 'owned reduce [self s]]
@hiiamboris
hiiamboris / constraints.txt
Created August 14, 2023 14:07
Argument and facet constraints from Spaces
(x >= 0)
(0 < length? s)
(none? y)
(none? m)
(same? type? X1 type? X2)
(xrange >= 0)
(frange >= 0)
(nmax > 0)
(find [binary interp jump] guess)
(host? host)
@hiiamboris
hiiamboris / silvermoon.theme
Created August 7, 2023 18:28
silvermoon theme
; Copyright © Microsoft Corp.
[Theme]
; High Contrast White - IDS_THEME_DISPLAYNAME_HCWHITE
DisplayName=silvermoon
ThemeId={ECCE8417-4571-4413-A4AD-680D75696797}
; Computer - SHIDI_SERVER
[CLSID\{20D04FE0-3AEA-1069-A2D8-08002B30309D}\DefaultIcon]
DefaultValue=%SystemRoot%\System32\imageres.dll,-109
@hiiamboris
hiiamboris / 1.red
Created July 28, 2023 12:45
Spiral text test
Red [needs: view]
drawn: [translate 200x200 push [rotate 0.0 scale 1.0 1.0 text -3x-203 "L"] push [rotate 2.40612197430267 scale 0.9993330561110004 0.9993330561110004 text -3x-203 "o"] push [rotate 5.113009195393174 scale 0.9985832759130133 0.9985832759130133 text -3x-203 "r"] push [rotate 6.917600676120176 scale 0.998083734999044 0.998083734999044 text -3x-203 "e"] push [rotate 9.62448789721068 scale 0.9973348921424416 0.9973348921424416 text -3x-203 "m"] push [rotate 13.835201352240352 scale 0.9961711420696419 0.9961711420696419 text -3x-203 " "] push [rotate 15.339027586179517 scale 0.9957558462169389 0.9957558462169389 text -3x-203 "i"] push [rotate 16.542088573330854 scale 0.9954237341943969 0.9954237341943969 text -3x-203 "p"] push [rotate 19.24897579442136 scale 0.9946768870847758 0.9946768870847758 text -3x-203 "s"] push [rotate 21.655097768724026 scale 0.9940134934134055 0.9940134934134055 text -3x-203 "u"] push [rotate 24.361984989814534 scale 0.9932677043800738 0.9932677043800738 text -3x-203 "m"]
@hiiamboris
hiiamboris / wtfapply.md
Last active May 17, 2023 08:33
interesting `apply` scenarios gathered in one place for comparison

unordered key/value pairs with word shortcuts (original mezz impl):

	apply parse [case part length  input: series rules: =rule=]

path + args + k/v pairs (hybrid):

	apply 'parse/:case/:part [series =rule= length]

operands then refinements (reduced k/v syntax):

@hiiamboris
hiiamboris / into.red
Last active February 22, 2023 18:49
Could INTO be a separate function without breaking the language semantics and/or vastly complicating the interpreter?
Red [title: "An experiment with INTO separation"]
; do %/d/devel/red/common/with.red
buffers*: []
into: func [buffer [series!]] [append/only buffers* buffer exit]
collect': function [code [block!]] [
also buffer: any [
take/last buffers*
@hiiamboris
hiiamboris / 1.red
Created February 9, 2023 18:43
R3/Red cross profiling parse test
REBOL [] Red []
using-replace: func[str][
replace/all str "??" #"¿"
replace/all str "!!" #"¡"
replace/all str "a'" #"á"
replace/all str "e'" #"é"
replace/all str "i'" #"í"
replace/all str "o'" #"ó"
replace/all str "u'" #"ú"
replace/all str "u:" #"ü"
@hiiamboris
hiiamboris / obj-size-plotter.red
Created November 3, 2022 17:04
object size plotter
Red [title: "object size plotter" needs 'view]
sizes: []
plot1: [0x0]
plot2: []
recycle/off
repeat i 70 [
insert spec: [none] to set-word! rejoin ["word" i]
recycle
initial: stats