From 419ba412758692661188591e1d883c0f4489d8f3 Mon Sep 17 00:00:00 2001 From: sejo Date: Thu, 15 Jul 2021 21:14:02 -0500 Subject: [PATCH] forth page --- src/forth.gmo | 52 +++++++++++++++++++++++++++++++++++++++++++++++ src/low-level.gmo | 1 + src/tw.txt | 1 + src/uxn.gmo | 7 +++---- 4 files changed, 57 insertions(+), 4 deletions(-) create mode 100644 src/forth.gmo diff --git a/src/forth.gmo b/src/forth.gmo new file mode 100644 index 0000000..47c9e6e --- /dev/null +++ b/src/forth.gmo @@ -0,0 +1,52 @@ +# forth + +stack-based and lightweight programming language. + +it uses the {postfix} notation. + +# reading + +this book has a great pace and nice illustrations + +=> https://www.forth.com/starting-forth starting forth book + +# some words + +## running words + +these are some words for doing arithmetic with paces (min/km) and velocities (km/hr) + +``` forth words +: ms>s swap 60 * + ; ( min segs -- segs ) +: hms>s ms>s swap 3600 * + ; ( hr min segs -- segs ) +: msd>s1k >r ms>s 1000 swap r> */ ; ( min segs metros -- segs1km ) +: paso>vel ms>s s1k>vel ; ( min segs -- vel ) +: s1k>vel 3600 swap / ; ( segs1km -- vel ) +: vel>s1k 3600 swap / ; ( vel -- segs1km ) +: .min 0 <# [CHAR] ' HOLD #S #> TYPE ; ( min -- ) +: .seg 0 <# [CHAR] " HOLD # # #> TYPE ; ( segs -- ) +: .ms 60 /mod .min .seg ; ( segs -- ) +: .vel . ." km/hr " ; +: lista-velocidades cr 21 10 do i dup . vel>s1k .ms cr loop ; +``` + +for example, to convert a velocity to a pace, and print it: + +``` input: 18, output: 3'20" +18 vel>s1k .ms +3'20" ok +``` + +to do the opposite operation: + +``` input: 3 20, output: 18 km/hr +3 20 ms>s s1k>vel .vel +18 km/hr ok +``` + +to get the pace of a given segment, using minutes, seconds and distance in meters: + +``` input: 1 03 300, output: 3'30" +1 03 300 msd>s1k .ms +3'30" ok +``` diff --git a/src/low-level.gmo b/src/low-level.gmo index a19b6db..fcaf88e 100644 --- a/src/low-level.gmo +++ b/src/low-level.gmo @@ -8,6 +8,7 @@ writing code closer to the machine(s) # software +=> ./forth.gmi {forth} => ./uxnería.gmi {uxnería} => ./nibble_dice_tracker.gmi {nibble dice tracker} => ./darena.gmi {darena} diff --git a/src/tw.txt b/src/tw.txt index a288222..27c42aa 100644 --- a/src/tw.txt +++ b/src/tw.txt @@ -2,6 +2,7 @@ # url = https://compudanzas.net/tw.txt # url = gemini://compudanzas.net/tw.txt # +2021-07-15T12:00:00-05:00 reading starting {forth}. possible practice, puzle, game, eventually dance? 2021-07-12T12:00:00-05:00 published the {uxnería} repo for {uxn} projects and sketches. excited about the {nibble dice tracker}! 2021-07-05T21:00:00-05:00 for the fourth session of the workshop we shared our máquina universal bailable {mub} - it was great to revisit it! 2021-06-30T21:00:00-05:00 in the third session of the workshop we learned and performed the {danzasistemas-tag} (first time ever!) and a turing machine in {d-turing} mode diff --git a/src/uxn.gmo b/src/uxn.gmo index 33c901d..a8c9026 100644 --- a/src/uxn.gmo +++ b/src/uxn.gmo @@ -1,6 +1,6 @@ # uxn -uxn is a little forth machine with 32 instructions. +uxn is a little {forth} machine with 32 instructions. => https://wiki.xxiivv.com/site/uxn.html uxn @@ -8,11 +8,10 @@ it uses the {postfix} notation. our projects and sketches are hosted in the {uxnería} -# notes -## common code structures +# common code structures -### loop with a counter +## loop with a counter loop with a structure that allows you to easily use the iteration counter: