unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* How to create hygienic environments?
@ 2015-06-19 14:39 Michael Tiedtke
  2015-06-19 22:08 ` Matt Wette
  0 siblings, 1 reply; 5+ messages in thread
From: Michael Tiedtke @ 2015-06-19 14:39 UTC (permalink / raw)
  To: guile-user

[-- Attachment #1: Type: text/plain, Size: 924 bytes --]

Does anyone know how I to create empty environments in Guile Scheme 
(preferably 1.8)?

The task at hand is well known: the user of an text editor can input 
complex commands with parameters (a little bit like in Emacs). Now I 
would like to /read/ these commands as single procedure calls with its 
parameters as an s-expression. But then how do I /eval/uate it in a 
special environment where only the editor commands are available by default?

The /(null-environment 5)/ gives me an empty environment but how should 
I insert the editor commands? Last time I checked (that was about some 
years ago when I didn't really need it) I found some C only routines but 
maybe I mixed them up with the UNIX process environment (variables).

How do I create a hygienic algorithmic text editor language within the 
Algorithmic Language Scheme?

Perhaps it's even better to give access to the usual Guile top level 
environment ...

[-- Attachment #2: Type: text/html, Size: 1208 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: How to create hygienic environments?
  2015-06-19 14:39 How to create hygienic environments? Michael Tiedtke
@ 2015-06-19 22:08 ` Matt Wette
  2015-06-20  4:54   ` Michael Tiedtke
  0 siblings, 1 reply; 5+ messages in thread
From: Matt Wette @ 2015-06-19 22:08 UTC (permalink / raw)
  To: guile-user


On Jun 19, 2015, at 7:39 AM, Michael Tiedtke <michele.titke@o2online.de> wrote:

> Does anyone know how I to create empty environments in Guile Scheme (preferably 1.8)?

There is a procedure null-environment.   Check the guile reference manual, start at "concept index".  The guile manual is quite extensive.




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: How to create hygienic environments?
  2015-06-19 22:08 ` Matt Wette
@ 2015-06-20  4:54   ` Michael Tiedtke
  2015-06-20 12:54     ` Neil Jerram
  0 siblings, 1 reply; 5+ messages in thread
From: Michael Tiedtke @ 2015-06-20  4:54 UTC (permalink / raw)
  To: guile-user

[-- Attachment #1: Type: text/plain, Size: 797 bytes --]



On 20/06/2015 00:08, Matt Wette wrote:
> On Jun 19, 2015, at 7:39 AM, Michael Tiedtke <michele.titke@o2online.de> wrote:
>
>> Does anyone know how I to create empty environments in Guile Scheme (preferably 1.8)?
> There is a procedure null-environment.   Check the guile reference manual, start at "concept index".  The guile manual is quite extensive.
>

Thank you. By now I know that "quite extensive manual" rather well - 
it's about ten years since I first read it
Just to quote myself:

 > The /(null-environment 5)/ gives me an empty environment but how 
should I insert the editor commands?

Just think of these editor commands as regular Scheme definitions.

By accident I found an option for secure modules which only gives you a 
safe set of Scheme definition - but not a clean start.

[-- Attachment #2: Type: text/html, Size: 1454 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: How to create hygienic environments?
  2015-06-20  4:54   ` Michael Tiedtke
@ 2015-06-20 12:54     ` Neil Jerram
  2015-06-20 13:16       ` Michael Tiedtke
  0 siblings, 1 reply; 5+ messages in thread
From: Neil Jerram @ 2015-06-20 12:54 UTC (permalink / raw)
  To: Michael Tiedtke; +Cc: guile-user

Michael Tiedtke <michele.titke@o2online.de> writes:


> Just to quote myself:
>
>> The (null-environment 5) gives me an empty environment but how
> should I insert the editor commands? 
>
> Just think of these editor commands as regular Scheme definitions.

I think you're looking for 'module-define!':

scheme@(guile-user)> (define n (null-environment 5))
scheme@(guile-user)> (eval 'car n)
ERROR: In procedure memoize-variable-access!:
ERROR: Unbound variable: car

Entering a new prompt.  Type `,bt' for a backtrace or `,q' to continue.
scheme@(#{ g3900}#) [1]> ,q
scheme@(guile-user)> (eval 'car (current-module))
$2 = #<procedure car (_)>
scheme@(guile-user)> (module-define! n 'car car)
scheme@(guile-user)> (eval 'car n)
$3 = #<procedure car (_)>

Hope that helps!

    Neil



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: How to create hygienic environments?
  2015-06-20 12:54     ` Neil Jerram
@ 2015-06-20 13:16       ` Michael Tiedtke
  0 siblings, 0 replies; 5+ messages in thread
From: Michael Tiedtke @ 2015-06-20 13:16 UTC (permalink / raw)
  To: guile-user

[-- Attachment #1: Type: text/plain, Size: 4470 bytes --]



On 20/06/2015 14:54, Neil Jerram wrote:
> Michael Tiedtke <michele.titke@o2online.de> writes:
>
>
>> Just to quote myself:
>>
>>> The (null-environment 5) gives me an empty environment but how
>> should I insert the editor commands?
>>
>> Just think of these editor commands as regular Scheme definitions.
> I think you're looking for 'module-define!':
>
> scheme@(guile-user)> (define n (null-environment 5))
> scheme@(guile-user)> (eval 'car n)
> ERROR: In procedure memoize-variable-access!:
> ERROR: Unbound variable: car
>
> Entering a new prompt.  Type `,bt' for a backtrace or `,q' to continue.
> scheme@(#{ g3900}#) [1]> ,q
> scheme@(guile-user)> (eval 'car (current-module))
> $2 = #<procedure car (_)>
> scheme@(guile-user)> (module-define! n 'car car)
> scheme@(guile-user)> (eval 'car n)
> $3 = #<procedure car (_)>
>
> Hope that helps!
>
>      Neil
>

Y E S, yes yes yes yes! Exactly that! THANK YOU! Why didn't they put it 
in the documentation for 1.8?? Yes, finally I can force my editor users 
to use my stripped down editor language and not just use /open/ on a 
file on the internal command line to /load-file/. But I could change RED 
(read eval display) to open port objects in editor buffers just to see 
it wait for a device file or socket ... well, let's see ...

;; DEFUNCT
;; nUI0c - last test case
;;
(use-modules (oop goops)
              (pretext)
              (terminal)
              (buffer)
              (buffer-view)
              (command-line-environment))

(define (switch-mode mode)
   (set! current-event-dispatcher mode))
(define (command-mode key-code)
   (case key-code
     ((#\:)    (cursor-home terminal) (display ":")
               (switch-mode command-line-mode))
     ((#\i)    (switch-mode insert-mode))
     ((#\k up)    (cursor-up       terminal))
     ((#\j down)  (cursor-down     terminal))
     ((#\l right) (cursor-forward  terminal))
     ((#\h left)  (cursor-backward terminal))))

(define command-line-buffer '())
(define key-code-enter #\newline)
(define (command-line-mode key-code)
   (display key-code)
   (case key-code
     ((#\cr)  (command-line-execute))
     ((#\esc) (set! command-line-buffer '())
              (switch-mode command-mode))
     (else
      (set! command-line-buffer
            (cons key-code command-line-buffer)))))

(define (command-line-execute)
   (define (R-E-D command-string)
     (display (eval-command-line (read-string command-string)
                                 my-command-interface)))
   (define (read-string string)
     (call-with-input-string string read))
   (let ((command (list->string
                   (reverse! command-line-buffer))))
     (set! command (string-append "(" command ")"))
     (cursor-home terminal)
     (my-debug "     Command: " command " END COMMAND ")
     (cursor-home terminal)
     (catch #t
            (lambda () (R-E-D command))
            (lambda (key . args)
              (apply throw key args))
              ;; (if (eq? 'quit key)
              ;;     (throw key)
              ;;     (switch-mode command-mode)))
            (lambda (key . args)
              (if (not (eq? 'quit key))
                  (backtrace))))
     (set! command-line-buffer '())))


;;
;; Events, Jumps and other Party Functions
(define (my-command-interface what . args)
   (case what
     ((exit) (clean-exit))
     ((open) (open-file (car args)))))
(define buffer-view (make <buffer-view> #:terminal terminal))
(define (open-file path)
   (let* ((buffer (load-file path))
          (view (make <buffer-view> #:buffer buffer
                                   #:terminal terminal)))
     (set! buffer-view view)
     (refresh view)))
(define (clean-exit)
   (tty-sane-mode my-port)
   (quit))
   ;(primitive-exit))
(define current-event-dispatcher command-mode)
(define (event-dispatcher key-code)
   (current-event-dispatcher key-code))
(define (the-pre-final-handler key . args)
   (tty-sane-mode my-port)
   (backtrace))
(define (the-final-handler key . args)
   (display " Oh dear, we're gone! ")
   (for-each display args)
   (newline))

;;
;; This would have been music on Telex
(define my-port (fdopen (port->fdes (current-output-port)) "r+0b"))
(define terminal (make <terminal> #:port my-port))
(full-reset terminal)
(tty-raw-mode my-port)
(cursor-home terminal)


;;
;; Catch all or ketcHUP
(catch #t (lambda ()
             (start-event-loop terminal event-dispatcher))
        the-final-handler
        the-pre-final-handler)


[-- Attachment #2: Type: text/html, Size: 6115 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-06-20 13:16 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-06-19 14:39 How to create hygienic environments? Michael Tiedtke
2015-06-19 22:08 ` Matt Wette
2015-06-20  4:54   ` Michael Tiedtke
2015-06-20 12:54     ` Neil Jerram
2015-06-20 13:16       ` Michael Tiedtke

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).