From 94f76a1565f09d189d9f2cef6d3df7860321709e Mon Sep 17 00:00:00 2001 From: Jose Antonio Ortega Ruiz Date: Sun, 23 May 2010 23:10:52 +0200 Subject: Racket support (PLT 5 needed). --- scheme/plt/geiser.rkt | 22 +++++ scheme/plt/geiser.ss | 22 ----- scheme/plt/geiser/autodoc.rkt | 189 ++++++++++++++++++++++++++++++++++++++ scheme/plt/geiser/autodoc.ss | 189 -------------------------------------- scheme/plt/geiser/completions.rkt | 31 +++++++ scheme/plt/geiser/completions.ss | 31 ------- scheme/plt/geiser/enter.rkt | 103 +++++++++++++++++++++ scheme/plt/geiser/enter.ss | 103 --------------------- scheme/plt/geiser/eval.rkt | 81 ++++++++++++++++ scheme/plt/geiser/eval.ss | 81 ---------------- scheme/plt/geiser/locations.rkt | 54 +++++++++++ scheme/plt/geiser/locations.ss | 54 ----------- scheme/plt/geiser/main.rkt | 49 ++++++++++ scheme/plt/geiser/main.ss | 49 ---------- scheme/plt/geiser/modules.rkt | 147 +++++++++++++++++++++++++++++ scheme/plt/geiser/modules.ss | 147 ----------------------------- scheme/plt/geiser/user.rkt | 57 ++++++++++++ scheme/plt/geiser/user.ss | 57 ------------ scheme/plt/geiser/utils.rkt | 27 ++++++ scheme/plt/geiser/utils.ss | 27 ------ 20 files changed, 760 insertions(+), 760 deletions(-) create mode 100644 scheme/plt/geiser.rkt delete mode 100644 scheme/plt/geiser.ss create mode 100644 scheme/plt/geiser/autodoc.rkt delete mode 100644 scheme/plt/geiser/autodoc.ss create mode 100644 scheme/plt/geiser/completions.rkt delete mode 100644 scheme/plt/geiser/completions.ss create mode 100644 scheme/plt/geiser/enter.rkt delete mode 100644 scheme/plt/geiser/enter.ss create mode 100644 scheme/plt/geiser/eval.rkt delete mode 100644 scheme/plt/geiser/eval.ss create mode 100644 scheme/plt/geiser/locations.rkt delete mode 100644 scheme/plt/geiser/locations.ss create mode 100644 scheme/plt/geiser/main.rkt delete mode 100644 scheme/plt/geiser/main.ss create mode 100644 scheme/plt/geiser/modules.rkt delete mode 100644 scheme/plt/geiser/modules.ss create mode 100644 scheme/plt/geiser/user.rkt delete mode 100644 scheme/plt/geiser/user.ss create mode 100644 scheme/plt/geiser/utils.rkt delete mode 100644 scheme/plt/geiser/utils.ss (limited to 'scheme/plt') diff --git a/scheme/plt/geiser.rkt b/scheme/plt/geiser.rkt new file mode 100644 index 0000000..29dff2a --- /dev/null +++ b/scheme/plt/geiser.rkt @@ -0,0 +1,22 @@ +;;; geiser.ss -- entry point + +;; Copyright (C) 2009 Jose Antonio Ortega Ruiz + +;; This program is free software; you can redistribute it and/or +;; modify it under the terms of the Modified BSD License. You should +;; have received a copy of the license along with this program. If +;; not, see . + +;; Start date: Sat Apr 25, 2009 22:36 + +;;; Code: + +(require version/utils) +(unless (version<=? "4.2" (version)) + (error 'geiser + "Mzscheme version 4.2 or better required (found ~a)" + (version))) + +(require geiser/user) + +;;; geiser.ss ends here diff --git a/scheme/plt/geiser.ss b/scheme/plt/geiser.ss deleted file mode 100644 index 29dff2a..0000000 --- a/scheme/plt/geiser.ss +++ /dev/null @@ -1,22 +0,0 @@ -;;; geiser.ss -- entry point - -;; Copyright (C) 2009 Jose Antonio Ortega Ruiz - -;; This program is free software; you can redistribute it and/or -;; modify it under the terms of the Modified BSD License. You should -;; have received a copy of the license along with this program. If -;; not, see . - -;; Start date: Sat Apr 25, 2009 22:36 - -;;; Code: - -(require version/utils) -(unless (version<=? "4.2" (version)) - (error 'geiser - "Mzscheme version 4.2 or better required (found ~a)" - (version))) - -(require geiser/user) - -;;; geiser.ss ends here diff --git a/scheme/plt/geiser/autodoc.rkt b/scheme/plt/geiser/autodoc.rkt new file mode 100644 index 0000000..c317d5c --- /dev/null +++ b/scheme/plt/geiser/autodoc.rkt @@ -0,0 +1,189 @@ +;;; autodoc.ss -- suport for autodoc echo + +;; Copyright (C) 2009, 2010 Jose Antonio Ortega Ruiz + +;; This program is free software; you can redistribute it and/or +;; modify it under the terms of the Modified BSD License. You should +;; have received a copy of the license along with this program. If +;; not, see . + +;; Start date: Sun May 03, 2009 14:45 + +#lang scheme + +(provide autodoc update-signature-cache get-help) + +(require geiser/utils geiser/modules geiser/locations scheme/help) + +(define (get-help symbol mod) + (with-handlers ((exn? (lambda (_) + (eval `(help ,symbol))))) + (eval `(help ,symbol #:from ,(ensure-module-spec mod))))) + +(define (autodoc ids) + (if (not (list? ids)) + '() + (map (lambda (id) (or (autodoc* id) (list id))) ids))) + +(define (autodoc* id) + (and + (symbol? id) + (let* ((loc (symbol-location* id)) + (name (car loc)) + (path (cdr loc)) + (sgns (and path (find-signatures path name id))) + (sgns (and sgns (if (list? sgns) sgns '())))) + (and sgns + `(,id + (name . ,name) + (args ,@(map format-signature sgns)) + (module . ,(module-path-name->name path))))))) + +(define (format-signature sign) + (if (signature? sign) + `((required ,@(signature-required sign)) + (optional ,@(signature-optional sign) + ,@(let ((rest (signature-rest sign))) + (if rest (list "...") '()))) + (key ,@(signature-keys sign))) + '())) + +(define signatures (make-hash)) + +(define-struct signature (required optional keys rest)) + +(define (find-signatures path name local-name) + (let ((path (if (path? path) (path->string path) path))) + (hash-ref! (hash-ref! signatures + path + (lambda () (parse-signatures path))) + name + (lambda () (infer-signatures local-name))))) + +(define (parse-signatures path) + (let ((result (make-hasheq))) + (with-handlers ((exn? (lambda (e) result))) + (with-input-from-file path + (lambda () + (parameterize ((read-accept-reader #t)) + (let loop ((stx (read-syntax path))) + (cond ((eof-object? stx) void) + ((syntax->datum stx) => + (lambda (datum) + (parse-datum! datum result) + (loop (read-syntax path)))) + (else void))))))) + result)) + +(define (parse-datum! datum store) + (with-handlers ((exn? (lambda (_) void))) + (match datum + (`(module ,name ,lang (#%module-begin . ,forms)) + (for-each (lambda (f) (parse-datum! f store)) forms)) + (`(module ,name ,lang . ,forms) + (for-each (lambda (f) (parse-datum! f store)) forms)) + (`(define ((,name . ,formals) . ,_) . ,_) + (add-signature! name formals store)) + (`(define (,name . ,formals) . ,_) + (add-signature! name formals store)) + (`(define ,name (lambda ,formals . ,_)) + (add-signature! name formals store)) + (`(define ,name (case-lambda ,clauses ...)) + (for-each (lambda (c) (add-signature! name (car c) store)) + (reverse clauses))) + (`(define-for-syntax (,name . ,formals) . ,_) + (add-signature! name formals store)) + (`(define-for-syntax ,name (lambda ,formals . ,_)) + (add-signature! name formals store)) + (`(define-syntax-rule (,name . ,formals) . ,_) + (add-signature! name formals store)) + (`(define-syntax ,name (syntax-rules ,specials . ,clauses)) + (for-each (lambda (c) (add-signature! name (cdar c) store)) + (reverse clauses))) + (`(define-syntax ,name (lambda ,_ (syntax-case ,_ . ,clauses))) + (for-each (lambda (c) (add-signature! name (cdar c) store)) + (reverse clauses))) + (_ void)))) + +(define (add-signature! name formals store) + (when (symbol? name) + (hash-set! store + name + (cons (parse-formals formals) + (hash-ref store name '()))))) + +(define (parse-formals formals) + (let loop ((formals formals) (req '()) (opt '()) (keys '())) + (cond ((null? formals) + (make-signature (reverse req) (reverse opt) (reverse keys) #f)) + ((symbol? formals) + (make-signature (reverse req) (reverse opt) + (reverse keys) formals)) + ((pair? (car formals)) (loop (cdr formals) + req + (cons (car formals) opt) + keys)) + ((keyword? (car formals)) (let* ((kname + (keyword->symbol (car formals))) + (arg-id (cadr formals)) + (name (if (pair? arg-id) + (list kname + (cadr arg-id)) + kname))) + (loop (cddr formals) + req + opt + (cons name keys)))) + (else (loop (cdr formals) (cons (car formals) req) opt keys))))) + +(define (infer-signatures name) + (define syntax-tag (cons 1 0)) + (define error-tag (cons 1 1)) + (define generic-signature (make-signature '(...) '() '() #f)) + (let ((value (with-handlers ((exn:fail:syntax? (lambda (_) syntax-tag)) + (exn:fail:contract:variable? (lambda (_) + error-tag))) + (namespace-variable-value name)))) + (cond ((procedure? value) (arity->signatures (procedure-arity value))) + ((eq? value syntax-tag) (list generic-signature)) + ((eq? value error-tag) #f) + (else 'variable)))) + +(define (arity->signatures arity) + (define (args fst count) + (let* ((letts (list->vector '(#\x #\y #\z #\u #\v #\w #\r #\s))) + (len (vector-length letts)) + (lett (lambda (n) (vector-ref letts (modulo n len))))) + (map (lambda (n) (string->symbol (format "~a" (lett n)))) + (build-list count (lambda (n) (+ n fst)))))) + (define (arity->signature arity) + (cond ((number? arity) + (make-signature (args 0 arity) '() '() #f)) + ((arity-at-least? arity) + (make-signature (args 0 (arity-at-least-value arity)) + '() '() 'rest)))) + (define (conseq? lst) + (cond ((< (length lst) 2) (number? (car lst))) + ((and (number? (car lst)) + (number? (cadr lst)) + (eqv? (+ 1 (car lst)) (cadr lst))) + (conseq? (cdr lst))) + (else #f))) + (cond ((and (list? arity) (conseq? arity)) + (let ((mi (apply min arity)) + (ma (apply max arity))) + (list (make-signature (args 0 mi) (args mi (- ma mi)) '() #f)))) + ((list? arity) (map arity->signature arity)) + (else (list (arity->signature arity))))) + +(define (update-signature-cache path . form) + (when (and (string? path) + (or (null? form) + (and (list? (car form)) + (not (null? (car form))) + (memq (caar form) + '(define-syntax-rule + define-syntax define set! define-struct))))) + (hash-remove! signatures path))) + +;;; autodoc.ss ends here diff --git a/scheme/plt/geiser/autodoc.ss b/scheme/plt/geiser/autodoc.ss deleted file mode 100644 index c317d5c..0000000 --- a/scheme/plt/geiser/autodoc.ss +++ /dev/null @@ -1,189 +0,0 @@ -;;; autodoc.ss -- suport for autodoc echo - -;; Copyright (C) 2009, 2010 Jose Antonio Ortega Ruiz - -;; This program is free software; you can redistribute it and/or -;; modify it under the terms of the Modified BSD License. You should -;; have received a copy of the license along with this program. If -;; not, see . - -;; Start date: Sun May 03, 2009 14:45 - -#lang scheme - -(provide autodoc update-signature-cache get-help) - -(require geiser/utils geiser/modules geiser/locations scheme/help) - -(define (get-help symbol mod) - (with-handlers ((exn? (lambda (_) - (eval `(help ,symbol))))) - (eval `(help ,symbol #:from ,(ensure-module-spec mod))))) - -(define (autodoc ids) - (if (not (list? ids)) - '() - (map (lambda (id) (or (autodoc* id) (list id))) ids))) - -(define (autodoc* id) - (and - (symbol? id) - (let* ((loc (symbol-location* id)) - (name (car loc)) - (path (cdr loc)) - (sgns (and path (find-signatures path name id))) - (sgns (and sgns (if (list? sgns) sgns '())))) - (and sgns - `(,id - (name . ,name) - (args ,@(map format-signature sgns)) - (module . ,(module-path-name->name path))))))) - -(define (format-signature sign) - (if (signature? sign) - `((required ,@(signature-required sign)) - (optional ,@(signature-optional sign) - ,@(let ((rest (signature-rest sign))) - (if rest (list "...") '()))) - (key ,@(signature-keys sign))) - '())) - -(define signatures (make-hash)) - -(define-struct signature (required optional keys rest)) - -(define (find-signatures path name local-name) - (let ((path (if (path? path) (path->string path) path))) - (hash-ref! (hash-ref! signatures - path - (lambda () (parse-signatures path))) - name - (lambda () (infer-signatures local-name))))) - -(define (parse-signatures path) - (let ((result (make-hasheq))) - (with-handlers ((exn? (lambda (e) result))) - (with-input-from-file path - (lambda () - (parameterize ((read-accept-reader #t)) - (let loop ((stx (read-syntax path))) - (cond ((eof-object? stx) void) - ((syntax->datum stx) => - (lambda (datum) - (parse-datum! datum result) - (loop (read-syntax path)))) - (else void))))))) - result)) - -(define (parse-datum! datum store) - (with-handlers ((exn? (lambda (_) void))) - (match datum - (`(module ,name ,lang (#%module-begin . ,forms)) - (for-each (lambda (f) (parse-datum! f store)) forms)) - (`(module ,name ,lang . ,forms) - (for-each (lambda (f) (parse-datum! f store)) forms)) - (`(define ((,name . ,formals) . ,_) . ,_) - (add-signature! name formals store)) - (`(define (,name . ,formals) . ,_) - (add-signature! name formals store)) - (`(define ,name (lambda ,formals . ,_)) - (add-signature! name formals store)) - (`(define ,name (case-lambda ,clauses ...)) - (for-each (lambda (c) (add-signature! name (car c) store)) - (reverse clauses))) - (`(define-for-syntax (,name . ,formals) . ,_) - (add-signature! name formals store)) - (`(define-for-syntax ,name (lambda ,formals . ,_)) - (add-signature! name formals store)) - (`(define-syntax-rule (,name . ,formals) . ,_) - (add-signature! name formals store)) - (`(define-syntax ,name (syntax-rules ,specials . ,clauses)) - (for-each (lambda (c) (add-signature! name (cdar c) store)) - (reverse clauses))) - (`(define-syntax ,name (lambda ,_ (syntax-case ,_ . ,clauses))) - (for-each (lambda (c) (add-signature! name (cdar c) store)) - (reverse clauses))) - (_ void)))) - -(define (add-signature! name formals store) - (when (symbol? name) - (hash-set! store - name - (cons (parse-formals formals) - (hash-ref store name '()))))) - -(define (parse-formals formals) - (let loop ((formals formals) (req '()) (opt '()) (keys '())) - (cond ((null? formals) - (make-signature (reverse req) (reverse opt) (reverse keys) #f)) - ((symbol? formals) - (make-signature (reverse req) (reverse opt) - (reverse keys) formals)) - ((pair? (car formals)) (loop (cdr formals) - req - (cons (car formals) opt) - keys)) - ((keyword? (car formals)) (let* ((kname - (keyword->symbol (car formals))) - (arg-id (cadr formals)) - (name (if (pair? arg-id) - (list kname - (cadr arg-id)) - kname))) - (loop (cddr formals) - req - opt - (cons name keys)))) - (else (loop (cdr formals) (cons (car formals) req) opt keys))))) - -(define (infer-signatures name) - (define syntax-tag (cons 1 0)) - (define error-tag (cons 1 1)) - (define generic-signature (make-signature '(...) '() '() #f)) - (let ((value (with-handlers ((exn:fail:syntax? (lambda (_) syntax-tag)) - (exn:fail:contract:variable? (lambda (_) - error-tag))) - (namespace-variable-value name)))) - (cond ((procedure? value) (arity->signatures (procedure-arity value))) - ((eq? value syntax-tag) (list generic-signature)) - ((eq? value error-tag) #f) - (else 'variable)))) - -(define (arity->signatures arity) - (define (args fst count) - (let* ((letts (list->vector '(#\x #\y #\z #\u #\v #\w #\r #\s))) - (len (vector-length letts)) - (lett (lambda (n) (vector-ref letts (modulo n len))))) - (map (lambda (n) (string->symbol (format "~a" (lett n)))) - (build-list count (lambda (n) (+ n fst)))))) - (define (arity->signature arity) - (cond ((number? arity) - (make-signature (args 0 arity) '() '() #f)) - ((arity-at-least? arity) - (make-signature (args 0 (arity-at-least-value arity)) - '() '() 'rest)))) - (define (conseq? lst) - (cond ((< (length lst) 2) (number? (car lst))) - ((and (number? (car lst)) - (number? (cadr lst)) - (eqv? (+ 1 (car lst)) (cadr lst))) - (conseq? (cdr lst))) - (else #f))) - (cond ((and (list? arity) (conseq? arity)) - (let ((mi (apply min arity)) - (ma (apply max arity))) - (list (make-signature (args 0 mi) (args mi (- ma mi)) '() #f)))) - ((list? arity) (map arity->signature arity)) - (else (list (arity->signature arity))))) - -(define (update-signature-cache path . form) - (when (and (string? path) - (or (null? form) - (and (list? (car form)) - (not (null? (car form))) - (memq (caar form) - '(define-syntax-rule - define-syntax define set! define-struct))))) - (hash-remove! signatures path))) - -;;; autodoc.ss ends here diff --git a/scheme/plt/geiser/completions.rkt b/scheme/plt/geiser/completions.rkt new file mode 100644 index 0000000..bf6b1c9 --- /dev/null +++ b/scheme/plt/geiser/completions.rkt @@ -0,0 +1,31 @@ +;;; completions.ss -- completion support + +;; Copyright (C) 2009 Jose Antonio Ortega Ruiz + +;; This program is free software; you can redistribute it and/or +;; modify it under the terms of the Modified BSD License. You should +;; have received a copy of the license along with this program. If +;; not, see . + +;; Start date: Sun Apr 26, 2009 19:02 + +#lang scheme + +(provide symbol-completions + module-completions) + +(require srfi/13 geiser/utils geiser/modules) + +(define (filter-prefix prefix lst sort?) + (filter (lambda (s) (string-prefix? prefix s)) + (if sort? (sort lst stringstring (namespace-mapped-symbols)) + #t)) + +(define (module-completions prefix) + (filter-prefix prefix (module-list) #f)) + +;;; completions.ss ends here diff --git a/scheme/plt/geiser/completions.ss b/scheme/plt/geiser/completions.ss deleted file mode 100644 index bf6b1c9..0000000 --- a/scheme/plt/geiser/completions.ss +++ /dev/null @@ -1,31 +0,0 @@ -;;; completions.ss -- completion support - -;; Copyright (C) 2009 Jose Antonio Ortega Ruiz - -;; This program is free software; you can redistribute it and/or -;; modify it under the terms of the Modified BSD License. You should -;; have received a copy of the license along with this program. If -;; not, see . - -;; Start date: Sun Apr 26, 2009 19:02 - -#lang scheme - -(provide symbol-completions - module-completions) - -(require srfi/13 geiser/utils geiser/modules) - -(define (filter-prefix prefix lst sort?) - (filter (lambda (s) (string-prefix? prefix s)) - (if sort? (sort lst stringstring (namespace-mapped-symbols)) - #t)) - -(define (module-completions prefix) - (filter-prefix prefix (module-list) #f)) - -;;; completions.ss ends here diff --git a/scheme/plt/geiser/enter.rkt b/scheme/plt/geiser/enter.rkt new file mode 100644 index 0000000..b81ba48 --- /dev/null +++ b/scheme/plt/geiser/enter.rkt @@ -0,0 +1,103 @@ +;;; enter.ss -- custom module loaders + +;; Copyright (C) 2010 Jose Antonio Ortega Ruiz + +;; This program is free software; you can redistribute it and/or +;; modify it under the terms of the Modified BSD License. You should +;; have received a copy of the license along with this program. If +;; not, see . + +;; Start date: Wed Mar 31, 2010 21:53 + +#lang scheme/base + +(require syntax/modcode + (for-syntax scheme/base)) + +(provide get-namespace enter-module module-loader module-loaded?) + +(define-struct mod (name timestamp depends)) + +(define loaded (make-hash)) + +(define (module-loaded? path) + (with-handlers ((exn? (lambda (_) #f))) + (let ((rp (module-path-index-resolve (module-path-index-join path #f)))) + (hash-has-key? loaded (resolved-module-path-name rp))))) + +(define (enter-module mod) + (dynamic-require mod #f) + (check-latest mod)) + +(define (module-loader orig) + (enter-load/use-compiled orig #f)) + +(define (notify re? path) + (when re? + (fprintf (current-error-port) " [re-loading ~a]\n" path))) + +(define inhibit-eval (make-parameter #f)) + +(define (get-namespace mod) + (parameterize ([inhibit-eval #t]) + (module->namespace mod))) + +(define ((enter-load/use-compiled orig re?) path name) + (when (inhibit-eval) + (raise (make-exn:fail "namespace not found" + (current-continuation-marks)))) + (if name + ;; Module load: + (let ([code (get-module-code path "compiled" compile + (lambda (ext loader?) + (load-extension ext) + #f) + #:notify (lambda (chosen) + (notify re? chosen)))] + [path (normal-case-path + (simplify-path + (path->complete-path path + (or (current-load-relative-directory) + (current-directory)))))]) + ;; Record module timestamp and dependencies: + (let ([mod (make-mod name + (get-timestamp path) + (if code + (apply append + (map cdr (module-compiled-imports code))) + null))]) + (hash-set! loaded path mod)) + ;; Evaluate the module: + (eval code)) + ;; Not a module: + (begin + (notify re? path) + (orig path name)))) + +(define (get-timestamp path) + (file-or-directory-modify-seconds path #f (lambda () -inf.0))) + +(define (check-latest mod) + (let ([mpi (module-path-index-join mod #f)] + [done (make-hash)]) + (let loop ([mpi mpi]) + (let* ([rpath (module-path-index-resolve mpi)] + [path (resolved-module-path-name rpath)]) + (when (path? path) + (let ([path (normal-case-path path)]) + (unless (hash-ref done path #f) + (hash-set! done path #t) + (let ([mod (hash-ref loaded path #f)]) + (when mod + (for-each loop (mod-depends mod)) + (let ([ts (get-timestamp path)]) + (when (ts . > . (mod-timestamp mod)) + (let ([orig (current-load/use-compiled)]) + (parameterize ([current-load/use-compiled + (enter-load/use-compiled orig #f)] + [current-module-declare-name rpath]) + ((enter-load/use-compiled orig #t) + path + (mod-name mod))))))))))))))) + +;;; enter.ss ends here diff --git a/scheme/plt/geiser/enter.ss b/scheme/plt/geiser/enter.ss deleted file mode 100644 index b81ba48..0000000 --- a/scheme/plt/geiser/enter.ss +++ /dev/null @@ -1,103 +0,0 @@ -;;; enter.ss -- custom module loaders - -;; Copyright (C) 2010 Jose Antonio Ortega Ruiz - -;; This program is free software; you can redistribute it and/or -;; modify it under the terms of the Modified BSD License. You should -;; have received a copy of the license along with this program. If -;; not, see . - -;; Start date: Wed Mar 31, 2010 21:53 - -#lang scheme/base - -(require syntax/modcode - (for-syntax scheme/base)) - -(provide get-namespace enter-module module-loader module-loaded?) - -(define-struct mod (name timestamp depends)) - -(define loaded (make-hash)) - -(define (module-loaded? path) - (with-handlers ((exn? (lambda (_) #f))) - (let ((rp (module-path-index-resolve (module-path-index-join path #f)))) - (hash-has-key? loaded (resolved-module-path-name rp))))) - -(define (enter-module mod) - (dynamic-require mod #f) - (check-latest mod)) - -(define (module-loader orig) - (enter-load/use-compiled orig #f)) - -(define (notify re? path) - (when re? - (fprintf (current-error-port) " [re-loading ~a]\n" path))) - -(define inhibit-eval (make-parameter #f)) - -(define (get-namespace mod) - (parameterize ([inhibit-eval #t]) - (module->namespace mod))) - -(define ((enter-load/use-compiled orig re?) path name) - (when (inhibit-eval) - (raise (make-exn:fail "namespace not found" - (current-continuation-marks)))) - (if name - ;; Module load: - (let ([code (get-module-code path "compiled" compile - (lambda (ext loader?) - (load-extension ext) - #f) - #:notify (lambda (chosen) - (notify re? chosen)))] - [path (normal-case-path - (simplify-path - (path->complete-path path - (or (current-load-relative-directory) - (current-directory)))))]) - ;; Record module timestamp and dependencies: - (let ([mod (make-mod name - (get-timestamp path) - (if code - (apply append - (map cdr (module-compiled-imports code))) - null))]) - (hash-set! loaded path mod)) - ;; Evaluate the module: - (eval code)) - ;; Not a module: - (begin - (notify re? path) - (orig path name)))) - -(define (get-timestamp path) - (file-or-directory-modify-seconds path #f (lambda () -inf.0))) - -(define (check-latest mod) - (let ([mpi (module-path-index-join mod #f)] - [done (make-hash)]) - (let loop ([mpi mpi]) - (let* ([rpath (module-path-index-resolve mpi)] - [path (resolved-module-path-name rpath)]) - (when (path? path) - (let ([path (normal-case-path path)]) - (unless (hash-ref done path #f) - (hash-set! done path #t) - (let ([mod (hash-ref loaded path #f)]) - (when mod - (for-each loop (mod-depends mod)) - (let ([ts (get-timestamp path)]) - (when (ts . > . (mod-timestamp mod)) - (let ([orig (current-load/use-compiled)]) - (parameterize ([current-load/use-compiled - (enter-load/use-compiled orig #f)] - [current-module-declare-name rpath]) - ((enter-load/use-compiled orig #t) - path - (mod-name mod))))))))))))))) - -;;; enter.ss ends here diff --git a/scheme/plt/geiser/eval.rkt b/scheme/plt/geiser/eval.rkt new file mode 100644 index 0000000..79f212e --- /dev/null +++ b/scheme/plt/geiser/eval.rkt @@ -0,0 +1,81 @@ +;;; eval.ss -- evaluation + +;; Copyright (C) 2009, 2010 Jose Antonio Ortega Ruiz + +;; This program is free software; you can redistribute it and/or +;; modify it under the terms of the Modified BSD License. You should +;; have received a copy of the license along with this program. If +;; not, see . + +;; Start date: Sun Apr 26, 2009 00:44 + +#lang scheme + +(provide eval-in + compile-in + load-file + compile-file + macroexpand + make-repl-reader) + +(require scheme/enter geiser/modules geiser/autodoc) + +(define last-result (void)) + +(define namespace->module-name + (compose module-path-name->name namespace->module-path-name)) + +(define last-namespace (make-parameter (current-namespace))) + +(define (exn-key e) + (vector-ref (struct->vector e) 0)) + +(define (set-last-error e) + (set! last-result `((error (key . ,(exn-key e))))) + (display (exn-message e))) + +(define (write-value v) + (with-output-to-string + (lambda () (write v)))) + +(define (set-last-result . vs) + (set! last-result `((result ,@(map write-value vs))))) + +(define (call-with-result thunk) + (set-last-result (void)) + (let ((output + (with-output-to-string + (lambda () + (with-handlers ((exn? set-last-error)) + (call-with-values thunk set-last-result)))))) + (append last-result `((output . ,output))))) + +(define (eval-in form spec lang) + (call-with-result + (lambda () + (update-signature-cache spec form) + (eval form (module-spec->namespace spec lang))))) + +(define compile-in eval-in) + +(define (load-file file) + (call-with-result + (lambda () + (load-module file (current-output-port) (last-namespace)) + (update-signature-cache file)))) + +(define compile-file load-file) + +(define (macroexpand form . all) + (let ((all (and (not (null? all)) (car all)))) + (with-output-to-string + (lambda () + (pretty-print (syntax->datum ((if all expand expand-once) form))))))) + +(define (make-repl-reader builtin-reader) + (lambda (ns) + (last-namespace ns) + (printf "racket@~a" (namespace->module-name ns)) + (builtin-reader))) + +;;; eval.ss ends here diff --git a/scheme/plt/geiser/eval.ss b/scheme/plt/geiser/eval.ss deleted file mode 100644 index e806138..0000000 --- a/scheme/plt/geiser/eval.ss +++ /dev/null @@ -1,81 +0,0 @@ -;;; eval.ss -- evaluation - -;; Copyright (C) 2009, 2010 Jose Antonio Ortega Ruiz - -;; This program is free software; you can redistribute it and/or -;; modify it under the terms of the Modified BSD License. You should -;; have received a copy of the license along with this program. If -;; not, see . - -;; Start date: Sun Apr 26, 2009 00:44 - -#lang scheme - -(provide eval-in - compile-in - load-file - compile-file - macroexpand - make-repl-reader) - -(require scheme/enter geiser/modules geiser/autodoc) - -(define last-result (void)) - -(define namespace->module-name - (compose module-path-name->name namespace->module-path-name)) - -(define last-namespace (make-parameter (current-namespace))) - -(define (exn-key e) - (vector-ref (struct->vector e) 0)) - -(define (set-last-error e) - (set! last-result `((error (key . ,(exn-key e))))) - (display (exn-message e))) - -(define (write-value v) - (with-output-to-string - (lambda () (write v)))) - -(define (set-last-result . vs) - (set! last-result `((result ,@(map write-value vs))))) - -(define (call-with-result thunk) - (set-last-result (void)) - (let ((output - (with-output-to-string - (lambda () - (with-handlers ((exn? set-last-error)) - (call-with-values thunk set-last-result)))))) - (append last-result `((output . ,output))))) - -(define (eval-in form spec lang) - (call-with-result - (lambda () - (update-signature-cache spec form) - (eval form (module-spec->namespace spec lang))))) - -(define compile-in eval-in) - -(define (load-file file) - (call-with-result - (lambda () - (load-module file (current-output-port) (last-namespace)) - (update-signature-cache file)))) - -(define compile-file load-file) - -(define (macroexpand form . all) - (let ((all (and (not (null? all)) (car all)))) - (with-output-to-string - (lambda () - (pretty-print (syntax->datum ((if all expand expand-once) form))))))) - -(define (make-repl-reader builtin-reader) - (lambda (ns) - (last-namespace ns) - (printf "mzscheme@~a" (namespace->module-name ns)) - (builtin-reader))) - -;;; eval.ss ends here diff --git a/scheme/plt/geiser/locations.rkt b/scheme/plt/geiser/locations.rkt new file mode 100644 index 0000000..dea93c6 --- /dev/null +++ b/scheme/plt/geiser/locations.rkt @@ -0,0 +1,54 @@ +;;; locations.ss -- locating symbols + +;; Copyright (C) 2009 Jose Antonio Ortega Ruiz + +;; This program is free software; you can redistribute it and/or +;; modify it under the terms of the Modified BSD License. You should +;; have received a copy of the license along with this program. If +;; not, see . + +;; Start date: Sun Apr 26, 2009 19:43 + +#lang scheme + +(provide symbol-location + symbol-location* + module-location + symbol-module-name + symbol-module-path-name) + +(require geiser/utils geiser/modules) + +(define (symbol-location* sym) + (let* ((id (namespace-symbol->identifier sym)) + (binding (and id (identifier-binding id)))) + (if (list? binding) + (cons + (cadr binding) + (resolved-module-path-name + (module-path-index-resolve (car binding)))) + (cons sym #f)))) + +(define (make-location name path line) + (list (cons 'name name) + (cons 'file (if (path? path) (path->string path) '())) + (cons 'line (or line '())))) + +(define (symbol-location sym) + (let* ((loc (symbol-location* sym)) + (name (car loc)) + (path (cdr loc))) + (if path + (make-location name path #f) + (module-location sym)))) + +(define symbol-module-path-name (compose cdr symbol-location*)) + +(define symbol-module-name + (compose module-path-name->name symbol-module-path-name)) + +(define (module-location sym) + (make-location sym (module-spec->path-name sym) 1)) + + +;;; locations.ss ends here diff --git a/scheme/plt/geiser/locations.ss b/scheme/plt/geiser/locations.ss deleted file mode 100644 index dea93c6..0000000 --- a/scheme/plt/geiser/locations.ss +++ /dev/null @@ -1,54 +0,0 @@ -;;; locations.ss -- locating symbols - -;; Copyright (C) 2009 Jose Antonio Ortega Ruiz - -;; This program is free software; you can redistribute it and/or -;; modify it under the terms of the Modified BSD License. You should -;; have received a copy of the license along with this program. If -;; not, see . - -;; Start date: Sun Apr 26, 2009 19:43 - -#lang scheme - -(provide symbol-location - symbol-location* - module-location - symbol-module-name - symbol-module-path-name) - -(require geiser/utils geiser/modules) - -(define (symbol-location* sym) - (let* ((id (namespace-symbol->identifier sym)) - (binding (and id (identifier-binding id)))) - (if (list? binding) - (cons - (cadr binding) - (resolved-module-path-name - (module-path-index-resolve (car binding)))) - (cons sym #f)))) - -(define (make-location name path line) - (list (cons 'name name) - (cons 'file (if (path? path) (path->string path) '())) - (cons 'line (or line '())))) - -(define (symbol-location sym) - (let* ((loc (symbol-location* sym)) - (name (car loc)) - (path (cdr loc))) - (if path - (make-location name path #f) - (module-location sym)))) - -(define symbol-module-path-name (compose cdr symbol-location*)) - -(define symbol-module-name - (compose module-path-name->name symbol-module-path-name)) - -(define (module-location sym) - (make-location sym (module-spec->path-name sym) 1)) - - -;;; locations.ss ends here diff --git a/scheme/plt/geiser/main.rkt b/scheme/plt/geiser/main.rkt new file mode 100644 index 0000000..f157ac6 --- /dev/null +++ b/scheme/plt/geiser/main.rkt @@ -0,0 +1,49 @@ +;;; main.ss -- exported interface for emacs + +;; Copyright (C) 2010 Jose Antonio Ortega Ruiz + +;; This program is free software; you can redistribute it and/or +;; modify it under the terms of the Modified BSD License. You should +;; have received a copy of the license along with this program. If +;; not, see . + +;; Start date: Wed Mar 31, 2010 21:14 + +;;; main.ss ends here + +#lang scheme/base + +(provide geiser:eval + geiser:compile + geiser:load-file + geiser:compile-file + geiser:macroexpand + geiser:completions + geiser:module-completions + geiser:symbol-location + geiser:module-location + geiser:module-exports + geiser:autodoc + geiser:help) + +(require geiser/eval + geiser/modules + geiser/completions + geiser/locations + geiser/autodoc) + +(define (geiser:eval lang) + (lambda (form spec) (eval-in form spec lang))) +(define geiser:compile compile-in) +(define geiser:load-file load-file) +(define geiser:compile-file compile-file) +(define geiser:autodoc autodoc) +(define geiser:help get-help) +(define geiser:completions symbol-completions) +(define geiser:module-completions module-completions) +(define geiser:symbol-location symbol-location) +(define geiser:module-location module-location) +(define geiser:module-exports module-exports) +(define geiser:macroexpand macroexpand) + +;;; main.ss ends here diff --git a/scheme/plt/geiser/main.ss b/scheme/plt/geiser/main.ss deleted file mode 100644 index f157ac6..0000000 --- a/scheme/plt/geiser/main.ss +++ /dev/null @@ -1,49 +0,0 @@ -;;; main.ss -- exported interface for emacs - -;; Copyright (C) 2010 Jose Antonio Ortega Ruiz - -;; This program is free software; you can redistribute it and/or -;; modify it under the terms of the Modified BSD License. You should -;; have received a copy of the license along with this program. If -;; not, see . - -;; Start date: Wed Mar 31, 2010 21:14 - -;;; main.ss ends here - -#lang scheme/base - -(provide geiser:eval - geiser:compile - geiser:load-file - geiser:compile-file - geiser:macroexpand - geiser:completions - geiser:module-completions - geiser:symbol-location - geiser:module-location - geiser:module-exports - geiser:autodoc - geiser:help) - -(require geiser/eval - geiser/modules - geiser/completions - geiser/locations - geiser/autodoc) - -(define (geiser:eval lang) - (lambda (form spec) (eval-in form spec lang))) -(define geiser:compile compile-in) -(define geiser:load-file load-file) -(define geiser:compile-file compile-file) -(define geiser:autodoc autodoc) -(define geiser:help get-help) -(define geiser:completions symbol-completions) -(define geiser:module-completions module-completions) -(define geiser:symbol-location symbol-location) -(define geiser:module-location module-location) -(define geiser:module-exports module-exports) -(define geiser:macroexpand macroexpand) - -;;; main.ss ends here diff --git a/scheme/plt/geiser/modules.rkt b/scheme/plt/geiser/modules.rkt new file mode 100644 index 0000000..829cf77 --- /dev/null +++ b/scheme/plt/geiser/modules.rkt @@ -0,0 +1,147 @@ +;;; modules.ss -- module metadata + +;; Copyright (C) 2009, 2010 Jose Antonio Ortega Ruiz + +;; This program is free software; you can redistribute it and/or +;; modify it under the terms of the Modified BSD License. You should +;; have received a copy of the license along with this program. If +;; not, see . + +;; Start date: Wed May 06, 2009 02:35 + +#lang scheme + +(provide load-module + ensure-module-spec + module-spec->namespace + namespace->module-path-name + module-path-name->name + module-spec->path-name + module-list + module-exports) + +(require srfi/13 syntax/modresolve syntax/modcode geiser/enter) + +(define (ensure-module-spec spec) + (cond ((symbol? spec) spec) + ((not (string? spec)) #f) + (else `(file ,spec)))) + +(define (module-spec->namespace spec (lang #f)) + (let ((spec (ensure-module-spec spec)) + (try-lang (lambda (_) + (with-handlers ((exn? (const (current-namespace)))) + (and lang + (begin + (load-module lang #f (current-namespace)) + (module->namespace lang))))))) + (or (and spec + (with-handlers ((exn? try-lang)) (get-namespace spec))) + (current-namespace)))) + +(define nowhere (open-output-nowhere)) + +(define (load-module spec (port #f) (ns #f)) + (parameterize ((current-error-port (or port nowhere))) + (enter-module (ensure-module-spec spec)) + (when (namespace? ns) + (current-namespace ns)))) + +(define (namespace->module-path-name ns) + (let ((rmp (variable-reference->resolved-module-path + (eval '(#%variable-reference) ns)))) + (and (resolved-module-path? rmp) + (resolved-module-path-name rmp)))) + +(define (module-spec->path-name spec) + (with-handlers ((exn? (lambda (_) #f))) + (let ((ns (module-spec->namespace (ensure-module-spec spec)))) + (namespace->module-path-name ns)))) + +(define (module-path-name->name path) + (cond ((path? path) + (let* ((path (path->string path)) + (cpaths (map (compose path->string path->directory-path) + (current-library-collection-paths))) + (prefix-len (lambda (p) + (let ((pl (string-length p))) + (if (= pl (string-prefix-length p path)) + pl + 0)))) + (lens (map prefix-len cpaths)) + (real-path (substring path (apply max lens)))) + (if (absolute-path? real-path) + (call-with-values (lambda () (split-path path)) + (lambda (_ basename __) (path->string basename))) + (regexp-replace "\\.[^./]*$" real-path "")))) + ((eq? path '#%kernel) "(kernel)") + ((string? path) path) + ((symbol? path) (symbol->string path)) + (else ""))) + +(define (skippable-dir? path) + (call-with-values (lambda () (split-path path)) + (lambda (_ basename __) + (member (path->string basename) '(".svn" "compiled"))))) + +(define path->symbol (compose string->symbol path->string)) + +(define (path->entry path) + (and (bytes=? (or (filename-extension path) #"") #"ss") + (let ((path (path->string path))) + (substring path 0 (- (string-length path) 3))))) + +(define (visit-module-path path kind acc) + (case kind + ((file) (let ((entry (path->entry path))) + (if entry (cons entry acc) acc))) + ((dir) (cond ((skippable-dir? path) (values acc #f)) + ((file-exists? (build-path path "main.ss")) + (cons (path->string path) acc)) + (else acc))) + (else acc))) + +(define (find-modules path acc) + (if (directory-exists? path) + (parameterize ((current-directory path)) + (fold-files visit-module-path acc)) + acc)) + +(define (known-modules) + (sort (foldl find-modules '() (current-library-collection-paths)) stringnamespace mod)))))) + +(define (startup) + (thread update-module-cache) + (void)) + +(startup) + +;;; modules.ss ends here diff --git a/scheme/plt/geiser/modules.ss b/scheme/plt/geiser/modules.ss deleted file mode 100644 index 829cf77..0000000 --- a/scheme/plt/geiser/modules.ss +++ /dev/null @@ -1,147 +0,0 @@ -;;; modules.ss -- module metadata - -;; Copyright (C) 2009, 2010 Jose Antonio Ortega Ruiz - -;; This program is free software; you can redistribute it and/or -;; modify it under the terms of the Modified BSD License. You should -;; have received a copy of the license along with this program. If -;; not, see . - -;; Start date: Wed May 06, 2009 02:35 - -#lang scheme - -(provide load-module - ensure-module-spec - module-spec->namespace - namespace->module-path-name - module-path-name->name - module-spec->path-name - module-list - module-exports) - -(require srfi/13 syntax/modresolve syntax/modcode geiser/enter) - -(define (ensure-module-spec spec) - (cond ((symbol? spec) spec) - ((not (string? spec)) #f) - (else `(file ,spec)))) - -(define (module-spec->namespace spec (lang #f)) - (let ((spec (ensure-module-spec spec)) - (try-lang (lambda (_) - (with-handlers ((exn? (const (current-namespace)))) - (and lang - (begin - (load-module lang #f (current-namespace)) - (module->namespace lang))))))) - (or (and spec - (with-handlers ((exn? try-lang)) (get-namespace spec))) - (current-namespace)))) - -(define nowhere (open-output-nowhere)) - -(define (load-module spec (port #f) (ns #f)) - (parameterize ((current-error-port (or port nowhere))) - (enter-module (ensure-module-spec spec)) - (when (namespace? ns) - (current-namespace ns)))) - -(define (namespace->module-path-name ns) - (let ((rmp (variable-reference->resolved-module-path - (eval '(#%variable-reference) ns)))) - (and (resolved-module-path? rmp) - (resolved-module-path-name rmp)))) - -(define (module-spec->path-name spec) - (with-handlers ((exn? (lambda (_) #f))) - (let ((ns (module-spec->namespace (ensure-module-spec spec)))) - (namespace->module-path-name ns)))) - -(define (module-path-name->name path) - (cond ((path? path) - (let* ((path (path->string path)) - (cpaths (map (compose path->string path->directory-path) - (current-library-collection-paths))) - (prefix-len (lambda (p) - (let ((pl (string-length p))) - (if (= pl (string-prefix-length p path)) - pl - 0)))) - (lens (map prefix-len cpaths)) - (real-path (substring path (apply max lens)))) - (if (absolute-path? real-path) - (call-with-values (lambda () (split-path path)) - (lambda (_ basename __) (path->string basename))) - (regexp-replace "\\.[^./]*$" real-path "")))) - ((eq? path '#%kernel) "(kernel)") - ((string? path) path) - ((symbol? path) (symbol->string path)) - (else ""))) - -(define (skippable-dir? path) - (call-with-values (lambda () (split-path path)) - (lambda (_ basename __) - (member (path->string basename) '(".svn" "compiled"))))) - -(define path->symbol (compose string->symbol path->string)) - -(define (path->entry path) - (and (bytes=? (or (filename-extension path) #"") #"ss") - (let ((path (path->string path))) - (substring path 0 (- (string-length path) 3))))) - -(define (visit-module-path path kind acc) - (case kind - ((file) (let ((entry (path->entry path))) - (if entry (cons entry acc) acc))) - ((dir) (cond ((skippable-dir? path) (values acc #f)) - ((file-exists? (build-path path "main.ss")) - (cons (path->string path) acc)) - (else acc))) - (else acc))) - -(define (find-modules path acc) - (if (directory-exists? path) - (parameterize ((current-directory path)) - (fold-files visit-module-path acc)) - acc)) - -(define (known-modules) - (sort (foldl find-modules '() (current-library-collection-paths)) stringnamespace mod)))))) - -(define (startup) - (thread update-module-cache) - (void)) - -(startup) - -;;; modules.ss ends here diff --git a/scheme/plt/geiser/user.rkt b/scheme/plt/geiser/user.rkt new file mode 100644 index 0000000..48b7dd5 --- /dev/null +++ b/scheme/plt/geiser/user.rkt @@ -0,0 +1,57 @@ +;;; user.ss -- global bindings visible to geiser users + +;; Copyright (C) 2010 Jose Antonio Ortega Ruiz + +;; This program is free software; you can redistribute it and/or +;; modify it under the terms of the Modified BSD License. You should +;; have received a copy of the license along with this program. If +;; not, see . + +;; Start date: Wed Mar 31, 2010 22:24 + +#lang scheme/base + +(provide enter!) + +(require geiser/enter geiser/eval (for-syntax scheme/base)) + +(define-syntax (enter! stx) + (syntax-case stx () + [(enter! mod) + (if (or (not (syntax-e #'mod)) + (module-path? (syntax->datum #'mod))) + #'(do-enter! 'mod) + (raise-syntax-error + #f + "not a valid module path, and not #f" + stx + #'mod))] + [_ (raise-syntax-error + #f + "bad syntax; should be `(enter! )'" + stx)])) + +(define orig-namespace (current-namespace)) + +(define (do-enter! mod) + (if mod + (begin + (enter-module mod) + (let ([ns (module->namespace mod)]) + (current-namespace ns) + (namespace-require 'geiser/user))) + (current-namespace orig-namespace))) + + +(define orig-loader (current-load/use-compiled)) + +(define (init) + (compile-enforce-module-constants #f) + (current-load/use-compiled (module-loader orig-loader)) + (current-prompt-read (compose (make-repl-reader (current-prompt-read)) + current-namespace))) + +(init) + +;;; user.ss ends here + diff --git a/scheme/plt/geiser/user.ss b/scheme/plt/geiser/user.ss deleted file mode 100644 index 48b7dd5..0000000 --- a/scheme/plt/geiser/user.ss +++ /dev/null @@ -1,57 +0,0 @@ -;;; user.ss -- global bindings visible to geiser users - -;; Copyright (C) 2010 Jose Antonio Ortega Ruiz - -;; This program is free software; you can redistribute it and/or -;; modify it under the terms of the Modified BSD License. You should -;; have received a copy of the license along with this program. If -;; not, see . - -;; Start date: Wed Mar 31, 2010 22:24 - -#lang scheme/base - -(provide enter!) - -(require geiser/enter geiser/eval (for-syntax scheme/base)) - -(define-syntax (enter! stx) - (syntax-case stx () - [(enter! mod) - (if (or (not (syntax-e #'mod)) - (module-path? (syntax->datum #'mod))) - #'(do-enter! 'mod) - (raise-syntax-error - #f - "not a valid module path, and not #f" - stx - #'mod))] - [_ (raise-syntax-error - #f - "bad syntax; should be `(enter! )'" - stx)])) - -(define orig-namespace (current-namespace)) - -(define (do-enter! mod) - (if mod - (begin - (enter-module mod) - (let ([ns (module->namespace mod)]) - (current-namespace ns) - (namespace-require 'geiser/user))) - (current-namespace orig-namespace))) - - -(define orig-loader (current-load/use-compiled)) - -(define (init) - (compile-enforce-module-constants #f) - (current-load/use-compiled (module-loader orig-loader)) - (current-prompt-read (compose (make-repl-reader (current-prompt-read)) - current-namespace))) - -(init) - -;;; user.ss ends here - diff --git a/scheme/plt/geiser/utils.rkt b/scheme/plt/geiser/utils.rkt new file mode 100644 index 0000000..ff8e695 --- /dev/null +++ b/scheme/plt/geiser/utils.rkt @@ -0,0 +1,27 @@ +;;; utils.ss -- generic utilities + +;; Copyright (C) 2009 Jose Antonio Ortega Ruiz + +;; This program is free software; you can redistribute it and/or +;; modify it under the terms of the Modified BSD License. You should +;; have received a copy of the license along with this program. If +;; not, see . + +;; Start date: Sun May 03, 2009 03:09 + +#lang scheme + +(provide pair->list + keyword->symbol + symbol->keyword) + +(define (pair->list pair) + (let loop ((d pair) (s '())) + (cond ((null? d) (reverse s)) + ((symbol? d) (reverse (cons d s))) + (else (loop (cdr d) (cons (car d) s)))))) + +(define keyword->symbol (compose string->symbol keyword->string)) +(define (symbol->keyword sym) (string->keyword (format "~a" sym))) + +;;; utils.ss ends here diff --git a/scheme/plt/geiser/utils.ss b/scheme/plt/geiser/utils.ss deleted file mode 100644 index ff8e695..0000000 --- a/scheme/plt/geiser/utils.ss +++ /dev/null @@ -1,27 +0,0 @@ -;;; utils.ss -- generic utilities - -;; Copyright (C) 2009 Jose Antonio Ortega Ruiz - -;; This program is free software; you can redistribute it and/or -;; modify it under the terms of the Modified BSD License. You should -;; have received a copy of the license along with this program. If -;; not, see . - -;; Start date: Sun May 03, 2009 03:09 - -#lang scheme - -(provide pair->list - keyword->symbol - symbol->keyword) - -(define (pair->list pair) - (let loop ((d pair) (s '())) - (cond ((null? d) (reverse s)) - ((symbol? d) (reverse (cons d s))) - (else (loop (cdr d) (cons (car d) s)))))) - -(define keyword->symbol (compose string->symbol keyword->string)) -(define (symbol->keyword sym) (string->keyword (format "~a" sym))) - -;;; utils.ss ends here -- cgit v1.2.3