Changeset 35452 in project


Ignore:
Timestamp:
04/27/18 20:49:04 (4 weeks ago)
Author:
svnwiki
Message:

Anonymous wiki edit for IP [213.52.73.118]: nrepl doc from its readme (markdown-svnwiki)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wiki/eggref/4/nrepl

    r34231 r35452  
    1212<procedure> (nrepl port [spawn])</procedure>
    1313
    14 Listen to TCP port {{port}} and (blockingly) wait for incoming
    15 connections.  {{(spawn in out)}} is called for each incomming
    16 connection, where {{in}} is the input port and {{out}} is the output port
    17 for the new TCP session.
     14Listen to TCP port {{port}} number and (blockingly) wait for incoming
     15connections.  {{(spawn)}} is called for each incomming connection
     16without arguments where {{current-input-port}}, {{current-output-port}}
     17and {{current-error-port}} are bound to the TCP connection.
    1818
    1919You can use {{spawn}}, for example, for authentication:
     
    2121<enscript highlight="scheme">   
    2222(nrepl 1234
    23        (lambda (in out)
     23       (lambda ()
    2424         (thread-start! ;; otherwise accept-loop will be blocked
    2525          (lambda ()
    26             (display ";; please enter an accept token: " out)
    27             (define token (read-line in))
     26            (display ";; please enter an accept token: ")
     27            (define token (read-line))
    2828            (if (equal? token "abc")
    29                 (nrepl-loop in out)
    30                 (begin (display ";; access denied\n" out)
    31                        (close-input-port in)
    32                        (close-output-port out)))))))
    33 </enscript>
    34 
    35 blockquoteYou can use {{(tcp-addresses in)}} and {{(tcp-port-numbers in)}} to find
    36 out where the new session is coming from.
     29                (nrepl-loop)
     30                (begin (print ";; access denied")
     31                       (close-input-port (current-input-port))
     32                       (close-output-port (current-output-port))
     33               (close-output-port (current-error-port))))))))
     34</enscript>
     35
     36blockquoteYou can use {{tcp-addresses}} and {{tcp-port-numbers}} to find out where
     37the new session is coming from.
    3738
    3839{{nrepl}} will loop for accepting incomming connections unless {{spawn}}
    3940returns {{#f}}.
    4041
    41 <procedure> (nrepl-loop in out [eval [read]])</procedure>
    42 
    43 Start a standard REPL-loop: print the prompt, read an s-expression
    44 from {{in}}, evaluate the expression, print the result to {{out}} and
    45 repeat forever. This can be used inside the optionally supplied
    46 {{spawn}}-procedure above.
     42<procedure> (nrepl-loop #!key eval read print writeln)</procedure>
     43
     44Start a standard REPL-loop: print the prompt, read an s-expression,
     45evaluate the expression, print the result and repeat. Exceptions are
     46reported and data is flushed. This can be used inside the optionally
     47supplied {{spawn}}-procedure above.
    4748
    4849
     
    7172{{nrepl}} plays very nicely with [[https://www.gnu.org/software/emacs/|Emacs]]! If you're used to running {{M-x
    7273run-scheme}} and sending source-code from buffers into your REPL, an
    73 {{nrepl}} endpoint can be used as a Scheme "interpreter". Specify that
    74 you want to run {{nc localhost 1234}} for your Scheme interpreter
    75 instead of the usual {{csi}}, and you get the functionality you're used
    76 to.
     74{{nrepl}} endpoint can be used as a Scheme interpreter. You can specify
     75that you want to use {{nrepl}} with a prefix. For example:
     76
     77    C-u M-x run-scheme RET nc localhost 1234
    7778
    7879Note that telling [[https://www.gnu.org/software/emacs/|Emacs]] that {{nc localhost 1234}} is your Scheme
    79 interpreter is tricky because {{C-u M-x run-scheme}} will not let you
    80 enter spaces. This can be solved by pressing {{C-q}} before pressing
     80interpreter is tricky because {{C-u M-x run-scheme}} might not let you
     81enter spaces. You can enter spaces by pressing {{C-q}} before pressing
    8182space.
    8283
     
    163164 (lambda ()
    164165   (nrepl 1234
    165           (lambda (i o)
     166          (lambda ()
    166167            (thread-start!
    167168             (lambda ()
    168                (nrepl-loop
    169                 i o (lambda (x) (with-main-mutex (lambda () (eval x)))))))))))
     169               (nrepl-loop eval: (lambda (x) (with-main-mutex (lambda () (eval x)))))))))))
    170170
    171171(define (game-step)
Note: See TracChangeset for help on using the changeset viewer.