Skip to content

Instantly share code, notes, and snippets.

@nedzadarek
Created June 21, 2019 13:03
Show Gist options
  • Save nedzadarek/d922de8c049e88de37a570c730732711 to your computer and use it in GitHub Desktop.
Save nedzadarek/d922de8c049e88de37a570c730732711 to your computer and use it in GitHub Desktop.
Linked list using only `path!`
Red [
author: {Nędza Darek}
license: {
- use/modify everywhere
- point to this gist/github
- no warranties
}
version: 0.0.1
]
p1: to-path bind [next a] context [next: 11]
; == next/a
p2: to-path bind [next a] context [next: 22]
; == next/a
p3: to-path bind [next a] context [next: 33]
; == next/a
p1/next
; == a
p1/next: p2
; == next/a
p2/next: p3
; == next/a
p3/next: p1
; next/next/next/...
p1/next
; == next/next/next/...
first p1
; == next
reduce first p1
; == 11
reduce first p1/next
; == 22
reduce first p1/next/next
; == 33
reduce first p1/next/next/next
; == 11
get-value: function [path] [reduce first path]
; == func [path][reduce first path]
get-value p1/next/next/next
; == 11
get-value p1/next/next
; == 33
set-next: function ['path] [set path (select (get path) 'next)]
pp: p1
; == next/next/next/...
get-value set-next pp
; == 22
get-value set-next pp
; == 33
get-value set-next pp
; == 11
get-value set-next pp
; == 22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment