From e2b07a5fd0bbaad232c717fb90a31d6c61d72bd4 Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Thu, 14 Jul 2022 20:06:50 -0400 Subject: Try to include previous variable definitions in REPL links --- md.bqn | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'md.bqn') diff --git a/md.bqn b/md.bqn index 4e1cb798..63a63d6d 100644 --- a/md.bqn +++ b/md.bqn @@ -200,6 +200,19 @@ Markdown ← {filename𝕊𝕩: ⟨¬ useEntity , entities ⊏˜ useEntity/ind , /useEntity⟩ } + # Function to build REPL link + # May include previous statements to define variables + makeLink ← { + lines ← names ← nline ← ⟨⟩ + { used‿assigned‿aline 𝕊 ls: + prev ← lines ⊏˜ ⍷∧ (names ∊ used) / nline + names ∾↩ assigned + nline ∾↩ (≠lines) + aline + lines ∾↩ ls + JoinLines prev ∾ 𝕩 + } + } + # Non-empty lines in code blocks have 4 leading spaces ProcCode ← { # Strip the leading spaces @@ -235,7 +248,21 @@ Markdown ← {filename𝕊𝕩: r ← show ('#'≠⊑∘⊢)◶⟨"",E⎊(ShowErr∘•CurrentError⊢)⟩⍟(0<≠∘⊢)¨ parts # Link that runs the code - lu ← tryURL ∾ Base64 ¯1 ↓ JoinLines parts + # Parse assignments and variables to add previous lines if needed + In ← 1=+⟜(↕2)⊸⍋ + Names ← (((-´"aA")×"AZ"⊸In)⊸+code) ⊔˜ 1-˜('_'≠code)⊸× + ma‿sp‿st ← {m∧code=𝕩}¨"↩ ‿" ⋄ id←sp