Last active
May 9, 2018 10:55
-
-
Save toomasv/63a0ee4b5e5c5df2d2d83d76eb884989 to your computer and use it in GitHub Desktop.
Experiment with conversions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Red [ | |
Needs: View | |
Author: "Toomas Vooglaid" | |
Date: 2018-01-12 | |
Purpose: {To study conversions between datatypes} | |
] | |
ctx: context [ | |
types: compose [ | |
hex #00000001 | |
local-file "file.red" | |
file %file.red | |
paren (to-paren [paren]) | |
red-file %red-file.red | |
logic (true) | |
set-word (to-set-word 'set-word) | |
block [a block] | |
bitset (charset "abc") | |
binary #{01} | |
char #"a" | |
email e@mail | |
float 1.0 | |
get-path (to-get-path [get path]) | |
get-word (to-get-word 'get-word) | |
hash (to-hash [hash]) | |
integer 1 | |
issue #issue | |
lit-path 'lit/path | |
lit-word 'lit-word | |
map #(map: 1) | |
none (none) | |
pair 1x1 | |
path (to-path [some path]) | |
percent 1% | |
refinement (to-refinement 'refinement) | |
set-path (to-set-path [set path]) | |
string "string" | |
tag <tag> | |
time 12:00 | |
typeset (to-typeset [typeset!]) | |
tuple 0.0.0.1 | |
url (to-url 'url) | |
word (to-word 'word) | |
date 2018-01-01 | |
] | |
;OS-path | |
;unset | |
;image | |
conversions: copy/part collect [ | |
foreach w words-of system/words [ | |
all [ | |
type: find/match to-string w "to-" | |
not find ["OS-path" "image" "unset"] type | |
keep w | |
] | |
] | |
] 35 | |
rheads: conver: funcs: r: fn: none | |
lay: copy [ | |
title "Conversion laboratory" | |
backdrop black | |
size 803x901 | |
origin 1x1 space 1x1 | |
style converted: box "" beige 299x24 | |
style pan: panel black font [size: 10] | |
rheads: pan 99x899 [origin 1x1 space 1x1] | |
conver: pan 599x899 [origin 1x1 space 1x1] | |
funcs: pan 140x899 with [extra: object [text: "mold" obj: object [color: beige]]] | |
[origin 1x1 space 1x1] | |
] | |
n: 0 | |
clear-reactions | |
foreach [type val] types [ | |
n: n + 1 | |
append first skip find lay 'rheads 3 compose [ | |
text 99x24 beige center (to-string type) with [font: parent/font] return | |
] | |
append first skip find lay 'conver 3 copy/deep compose [ | |
field 299x24 no-border center (mold :val) with [font: parent/font] | |
converted with [font: parent/font] | |
return | |
] | |
append last lay compose [ | |
text 99x24 beige center (mold pick conversions n) | |
with [font: parent/font] | |
on-down [ | |
funcs/extra/obj/color: beige | |
funcs/extra/obj: face | |
funcs/extra/text: face/text | |
face/color: wheat | |
foreach [val var] conver/pane [ | |
err?: error? try [r: do reduce [load face/text val/data]] | |
var/text: either err? [""][mold :r] | |
] | |
] | |
return | |
] | |
] | |
lay: layout lay | |
foreach [a b] conver/pane [ | |
react/link func [trg src2][ | |
err?: error? try [r: do reduce [load funcs/extra/text src2/data]] | |
trg/text: either err? [""][mold :r] | |
] [b a] | |
] | |
view/flags lay [resize] | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment