Changeset 21987 in project


Ignore:
Timestamp:
12/14/10 13:51:44 (9 years ago)
Author:
Mario Domenech Goulart
Message:

Getting started (wiki manual): added enscript tag for code examples

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wiki/man/4/Getting started

    r21986 r21987  
    352352included with CHICKEN.
    353353
    354  (use regex)
    355  (define (process-line line re rplc)
    356    (string-substitute re rplc line 'all))
    357  (define (quickrep re rplc)
    358    (let ((line (read-line)))
    359      (if (not (eof-object? line))
    360          (begin
    361            (display (process-line line re rplc))
    362            (newline)
    363            (quickrep re rplc)))))
    364  ;;; Does a lousy job of error checking!
    365  (define (main args)
    366    (quickrep (regexp (car args)) (cadr args)))
     354<enscript highlight=scheme>
     355(use regex)
     356
     357(define (process-line line re rplc)
     358  (string-substitute re rplc line 'all))
     359
     360(define (quickrep re rplc)
     361  (let ((line (read-line)))
     362    (if (not (eof-object? line))
     363        (begin
     364          (display (process-line line re rplc))
     365          (newline)
     366          (quickrep re rplc)))))
     367
     368;;; Does a lousy job of error checking!
     369(define (main args)
     370  (quickrep (regexp (car args)) (cadr args)))
     371</enscript>
    367372
    368373The {{-ss}} option arranges to call a procedure named {{main}}, with
     
    410415palindrome.
    411416
    412  (define (palindrome? x)
    413    (define (check left right)
    414      (if (>= left right)
    415          #t
    416          (and (char=? (string-ref x left) (string-ref x right))
    417               (check (add1 left) (sub1 right)))))
    418    (check 0 (sub1 (string-length x))))
    419  (let ((arg (car (command-line-arguments))))
    420    (display
    421     (string-append arg
    422                    (if (palindrome? arg)
    423                        " is a palindrome\n"
    424                        " isn't a palindrome\n"))))
    425  
     417<enscript highlight=scheme>
     418(define (palindrome? x)
     419  (define (check left right)
     420    (if (>= left right)
     421        #t
     422        (and (char=? (string-ref x left) (string-ref x right))
     423             (check (add1 left) (sub1 right)))))
     424  (check 0 (sub1 (string-length x))))
     425(let ((arg (car (command-line-arguments))))
     426  (display
     427   (string-append arg
     428                  (if (palindrome? arg)
     429                      " is a palindrome\n"
     430                      " isn't a palindrome\n"))))
     431</enscript>
     432
    426433We can compile this program using {{csc}}, creating an executable
    427434named {{palindrome}}.
     
    443450eggs.)
    444451
    445  ;;; Library pal-proc.scm
    446  (declare (unit pal-proc))
    447  (define (palindrome? x)
    448    (define (check left right)
    449      (if (>= left right)
    450          #t
    451          (and (char=? (string-ref x left) (string-ref x right))
    452               (check (add1 left) (sub1 right)))))
    453    (check 0 (sub1 (string-length x))))
     452<enscript highlight=scheme>
     453;;; Library pal-proc.scm
     454(declare (unit pal-proc))
     455(define (palindrome? x)
     456  (define (check left right)
     457    (if (>= left right)
     458        #t
     459        (and (char=? (string-ref x left) (string-ref x right))
     460             (check (add1 left) (sub1 right)))))
     461  (check 0 (sub1 (string-length x))))
     462</enscript>
    454463
    455464Next we have some  client code that `uses' this separately-compiled
    456465module. 
    457466
    458  ;;; Client pal-user.scm
    459  (declare (uses pal-proc))
    460  (let ((arg (car (command-line-arguments))))
    461    (display
    462     (string-append arg
    463                    (if (palindrome? arg)
    464                        " is a palindrome\n"
    465                        " isn't a palindrome\n"))))
     467<enscript highlight=scheme>
     468;;; Client pal-user.scm
     469(declare (uses pal-proc))
     470(let ((arg (car (command-line-arguments))))
     471  (display
     472   (string-append arg
     473                  (if (palindrome? arg)
     474                      " is a palindrome\n"
     475                      " isn't a palindrome\n"))))
     476</enscript>
    466477
    467478Now we can compile and link everything together. (We show the compile
Note: See TracChangeset for help on using the changeset viewer.