From a4994371c0b0fbea9d2802acc22d9cc3977a0de0 Mon Sep 17 00:00:00 2001 From: Cliff Click Date: Sun, 4 Oct 2026 13:30:41 -0700 Subject: Slides for 2026 REBASE --- docs/2026_REBASE/language.js | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 docs/2026_REBASE/language.js (limited to 'docs/2026_REBASE/language.js') diff --git a/docs/2026_REBASE/language.js b/docs/2026_REBASE/language.js new file mode 100644 index 00000000..d5e1079a --- /dev/null +++ b/docs/2026_REBASE/language.js @@ -0,0 +1,40 @@ +/* Chapter 22 library explorer and Chapter 23 methods example. No fetch needed. */ +(function () { + const R=window.REBASE, esc=R.escape, files=R.library.files; + const parent=path=>path.split('/').slice(0,-1).join('/'); + const button=(path,label,cls='')=>''; + R.libraryHasPath=path=>typeof path==='string' && (path==='' || Object.hasOwn(files,path) || Object.keys(files).some(file=>file.startsWith(path+'/'))); + function explorer(state) { + const path=state.library, isFile=Object.hasOwn(files,path); + let crumbs=button('','Standard library'); + path.split('/').filter(Boolean).forEach((part,i,parts)=>{ + crumbs+='/'+button(parts.slice(0,i+1).join('/'),esc(part)); + }); + let contents; + if(isFile) { + contents='
'+esc(files[path])+'
'; + } else { + const entries=new Map(), prefix=path?path+'/':''; + for(const file of Object.keys(files)) if(file.startsWith(prefix)) { + const rest=file.slice(prefix.length), name=rest.split('/')[0]; + entries.set(name,rest.includes('/')); + } + contents='
'+ + [...entries].sort(([a,ad],[b,bd])=>Number(bd)-Number(ad)||a.localeCompare(b)).map(([name,dir])=> + button(prefix+name,''+(dir?'DIR':'SMP')+''+esc(name)+(dir?'/':'')+''+(dir?'›':'↗')+'','library-entry')).join('')+'
'; + } + return '
'+(isFile?'':'')+'

Chapter 25 · '+esc(R.library.origin)+'

'+contents+'
'; + } + function intro(which,state) { + const methods=which==='methods'; + return '
'; + } + function methods(state) { + return '
23 · Counter
'+esc(R.library.methods)+'

c.add(3).add(4) passes c as self.
The program returns arg + 7.

'; + } + R.languageBody=state=>'

The language starts
using its compiler.

'+ + (state.library===null?intro('library',state):explorer(state))+ + (state.library!==null && state.libraryWide?'':state.methods?methods(state):intro('methods',state))+'
'; +})(); -- cgit v1.2.3