• R/O
  • HTTP
  • SSH
  • HTTPS

提交

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

A categorical programming language


Commit MetaInfo

修订版b53ed5e7e011600ece82fbf6de1f0fa179c1c70a (tree)
时间2023-03-30 12:02:58
作者Corbin <cds@corb...>
CommiterCorbin

Log Message

Basic template-saving abilities for the REPL.

更改概述

差异

--- a/movelist/cammy-repl.scm
+++ b/movelist/cammy-repl.scm
@@ -175,7 +175,7 @@
175175 (car tys))))
176176
177177 (define (cammy-display-template expr)
178- (set! most-recent-template expr)
178+ (set! most-recent-template (pack-template expr))
179179 (display expr) (display (format-type-judgement (expr->ty expr))) (newline))
180180
181181 (define (cammy-display index)
@@ -191,6 +191,12 @@
191191
192192 (define hive '((heap) (symbols) (templates)))
193193
194+(define pack-template
195+ (match-lambda
196+ [(? number? n) n]
197+ [(? symbol? sym) (symbol->string sym)]
198+ [(h . t) (list->vector (cons (symbol->string h) (map pack-template t)))]))
199+
194200 (define resolve
195201 (match-lambda
196202 [(? symbol? sym) sym]
@@ -431,6 +437,19 @@
431437 (cons (cons name (vector melted "")) symbols))))
432438 (begin (display "Need a name, sorry.") (newline))))
433439
440+(define (cammy-template name)
441+ (if (symbol? name)
442+ (let* ((templates (json-assv 'templates hive))
443+ (record (json-assv name templates)))
444+ (if record
445+ (begin
446+ (display "Warning: Shadowing prior binding: ")
447+ (display (resolve (vector-ref record 0))) (newline)
448+ (vector-set! record 0 most-recent-template))
449+ (set-cdr! (assv 'templates hive)
450+ (cons (cons name (vector most-recent-template "")) templates))))
451+ (begin (display "Need a name, sorry.") (newline))))
452+
434453 (define help "Basic usage: Enter a Cammy expression to preview its elements.
435454
436455 When an expression is valid, it will be saved to '_'.
@@ -442,6 +461,10 @@ When an expression is valid, it will be saved to '_'.
442461 To give a name to _, 'dip' it with the desired name:
443462 > dip my/cool/func
444463
464+Similarly, templates can be saved:
465+ > (pr 0 1)
466+ > template my/cool/pr
467+
445468 To enter a template, use literal nats as De Bruijn indices. If you're used to
446469 the classic '(template @0 @1)' syntax, just use '(template 0 1)' instead.
447470
@@ -503,6 +526,7 @@ To write the hive, give a filename explicitly:
503526 ['animate (cammy-animate (lookup (read)))]
504527 ['search (display (cammy-search (symbol->string (read)))) (newline)]
505528 ['dip (cammy-dip (read))]
529+ ['template (cammy-template (read))]
506530 ['save
507531 (with-output-to-file (read) (lambda () (write-json hive)))
508532 (display "Wrote hive to file.") (newline)]