💾 Archived View for tozip.chickenkiller.com › guile.gmi captured on 2023-05-24 at 17:47:26. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2023-03-20)

➡️ Next capture (2023-06-16)

-=-=-=-=-=-=-

Guile programming language

Created 2022-07-07 Updated 2022-12-01

Anaphoric if

(define-syntax aif-version-1
  (lambda (x)
    (syntax-case x ()
      ((_ test then else)
       (with-syntax ((it (datum->syntax x 'it)))
         #'(let ((it test))
             (if it then else)))))))

(define-macro (aif-version-2 test then else)
              `(let ((it ,test))
                 (if it ,then ,else)))

(aif-version-2 2 (+ 1 it) 'bomb) ; => 3

Responses to the above code:

ctrl-c: Common Lisp Anaphoric IF

idiomdrottning: A problem with Guile’s defmacro

ports

Read the output from a command:

(use-modules (ice-9 popen))


(define (read-command-v1 cmd)
  (define port (open-input-pipe cmd))
  (define str    (reverse-list->string     
                   (let loop ((char (read-char port))
                              (result '()))
                     ;(display char)
                     (if (eof-object? char)
                       result           
                       (loop (read-char port) (cons char result))))))    
  (close-pipe port)    
  str)

(define (read-command-v2 cmd)
  (with-input-from-port (open-input-pipe cmd) read-string))

(display (read-command-v2 "ls -hal"))

See also:

client.scm

procedures

cut: srfi-26

Exits

pipes: for reading or writing to system commands

SRFI 8: receive: Binding to multiple values