[Chicken-users] Re: stressing the new hygienic macros

2009-05-01 Thread Michele Simionato
Does require-for-syntax work with Chicken 4?
As an exercise, I was trying to define a simple define macro as follows:

(require-for-syntax 'matchable)

(define-syntax def
  (lambda (x r c)
 (match x
  (('def (name . args) body body* ...)
   `(define ,name (lambda ,args ,body ,@body*)))
  (('def name value) `(define ,name ,value

That should work, isn't it? However I get

Error: unbound variable: require-for-syntax

Maybe things have changed, or maybe I have simply forgotten the right
incantations, I have been a few years without touching Chicken, and
searching the Chicken Wiki for require-for-syntax does not give
immediately useful info (it points mostly to Chicken 3 pages).
Help is appreciated!


___
Chicken-users mailing list
Chicken-users@nongnu.org
http://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] Re: stressing the new hygienic macros

2009-05-01 Thread Michele Simionato
On Fri, May 1, 2009 at 6:12 PM, Jim Ursetto zbignie...@gmail.com wrote:

 You want

 (require-library matchable)
 (import-for-syntax matchable)

Works like a charm, thanks. BTW, are there already libraries
marrying low level macros with matchable?


___
Chicken-users mailing list
Chicken-users@nongnu.org
http://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] stressing the new hygienic macros

2009-04-29 Thread Michele Simionato
On Tue, Apr 28, 2009 at 7:08 PM, Alex Shinn alexsh...@gmail.com wrote:
 Michele Simionato michele.simion...@gmail.com writes:
 Chicken 4 extends define-syntax with the er-macro-transformer spec,
 (and with raw lambdas which mean the same thing), but these
 are hard-coded.

 Al* Petrofsky specifically argued that this be allowed, as
 well as

  (let-syntax ((foo some-other-macro))
    ...)

 and implemented it in his alexpander.  It's a necessary
 feature for the user to provide his/her own syntax
 transformers defined in terms of existing transformers
 (e.g. super-syntax-rules with extended pattern matching).

 The other syntactic-closures and riaxpander macros systems
 in Chicken 3 also support it, as do MIT Scheme, Ikarus and
 Chibi-Scheme.  PLT doesn't.

PLT does, I have tested it in R6RS mode; it requires some incantation
with metalevels though.

Anyway, this is bad news for me. It means that if I want to define
my own syntax transformers I have to implement them from
scratch from low level macros :-(

My final purpose would be to port my sweet-macros
system to Chicken; see episode #9 of my
Adventures: http://www.artima.com/weblogs/viewpost.jsp?thread=251474


___
Chicken-users mailing list
Chicken-users@nongnu.org
http://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] stressing the new hygienic macros

2009-04-29 Thread Michele Simionato
On Wed, Apr 29, 2009 at 1:36 PM, Alex Shinn alexsh...@gmail.com wrote:
 Michele Simionato michele.simion...@gmail.com writes:

 Anyway, this is bad news for me. It means that if I want to define
 my own syntax transformers I have to implement them from
 scratch from low level macros :-(

 No, you can't define your own _transformers_ (the things you
 pass to define-syntax) with either low or high-level macros.
 The limitation is not in syntax-rules, it's in
 define-syntax, let-syntax and letrec-syntax.

Yep, I understood that.

 However, looking at your sweet macros, you can implement
 def-syntax in either low or high-level macros.  Just define
 a def-syntax macro that expands into a define-syntax macro.

 The problem is that then this can't be used conveniently
 with let-syntax and letrec-syntax.  So if you want to define
 your own macro extensions, you need to provide:

  my-define-syntax
  my-let-syntax
  my-letrec-syntax

 These would then not be composable with any other macro
 extensions.

This is exactly the issue I am unhappy with :-(


___
Chicken-users mailing list
Chicken-users@nongnu.org
http://lists.nongnu.org/mailman/listinfo/chicken-users


[Chicken-users] stressing the new hygienic macros

2009-04-28 Thread Michele Simionato
I have subscribed again the list after a few years of absence, because I wanted
to try the new and improved hygienic Chicken ;-)
As first experiment, I tried to stress a bit syntax-rules. I tried the following
at the REPL:

 (define-syntax very-static-table
  (syntax-rules ()
((_ (name value) ...)
  (syntax-rules (names name ...)
((_ names) '(name ...))
((_ name) value) ...

  (define-syntax color
  (very-static-table (red 0) (green 1) (blue 2)))

Error: unbound variable: red

Call history:

syntax(define-syntax color (very-static-table (red 0) 
(green 1) (blue 2)))
syntax(very-static-table (red 0) (green 1) (blue 2))
syntax(red 0)
syntax(green 1)
syntax(blue 2)
eval  (very-static-table (red 0) (green 1) (blue 2))
eval  (red 0) --

What's happening here? Notice that

 (define-syntax color
  (syntax-rules (names red green blue)
((_ names) '(red green blue))
((_ red) 0)
((_ green) 1)
((_ blue) 2)))

works as intended.


___
Chicken-users mailing list
Chicken-users@nongnu.org
http://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] Choosing a programming language for a web project

2007-10-01 Thread Michele Simionato
On 10/2/07, Graham Fawcett [EMAIL PROTECTED] wrote:
 In reply to an off-list message:
  Perhaps it is just me (I don't know much about these protocols), but I do
  not see the added value of yet another FastCGI/SCGI kind of interface.

 WSGI is not another FastCGI/SCGI: it's a boundary between a
 front-end protocol handler (such as an HTTP server, SCGI server, or
 a CGI environment) and the back-end application framework. From the
 framework's perspective, it provides an abstract model of what a
 request looks like, and how to submit a response. With something like
 WSGI, you could move your application from CGI to SCGI (for example)
 without any significant rewriting of your code.

I will just add a relevant link:
http://wsgi.org/wsgi

See also the WSGI 2.0 specification, where the minimal application is something
like

def app(environ):
return '200 OK', [('Content-type', 'text/plain')], ['Hello world']

 In my own mini-framework, my SCGI handler reads the request headers
 into an a-list. (In SCGI, request headers are represented by CGI-style
 environment variables.) The current input port is partially read by
 the SCGI handler (to get the headers), but the rest of the request is
 left for the framework to read. The framework is required to consume
 the remainder of the request.

 Response headers are represented by an (initially empty) a-list. The
 current-output-port is mapped to a string-port: collecting the output
 makes error-handling easier, and the buffering makes network
 communication more efficient. When the framework has finished writing
 the response, the SCGI handler consumes the response a-list, and the
 string-port's value, and sends it back to the Web server in SCGI
 format.

 So, in my WSGI-like interface for Chicken, a request/response pair is
 a 4-tuple, (incoming-request-headers, current-input-port,
 current-output-port, outgoing-response-headers). The application
 framework is represented by a single procedure that takes a 4-tuple as
 an argument, and returns no value. Upon an inbound request, the
 protocol side calls the procedure, and afterward it processes the
 outbound headers and output string-port.

 That, I think, is about as minimal as you can get, while still being
 robust and being flexible enough to accommodate many protocols and
 many app frameworks.

 Thoughts?

I am not convinced by the current-output-port. In WSGI you return an
iterator over strings (say a list) so that middleware can further process it.
Post-processing the current-output-port looks more cumbersome.
Just my 0.02c,

  Michele Simionato


___
Chicken-users mailing list
Chicken-users@nongnu.org
http://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] Integrating unit tests into source code

2006-12-14 Thread Michele Simionato

On 12/14/06, felix winkelmann [EMAIL PROTECTED] wrote:

Hi!

While reading a bit about doctest (the Python utility), I thought
it would be relatively easy to support embedded documentation
in definitions, like:

(define (foo ...)
  '(test (...))
  body...)

The basic idea is to extend the idea of Lisp/Scheme docstrings
(a string as the first form inside a procedure, when the body
has more than one expression) to doc-sexprs.
So one could embed test-cases directly in the code, in a backwards-
and R5RS-compatible way.

It's no big deal to extend the compiler to extract this info. What I'm
looking for is ideas about the exact mechanism, the syntax, etc.

Pointless or useful?


I am an heavy user of doctests, I have given a couple of talks on
the subject, and I have experimented a lot with them.

FWIW, this is what I do:

1. I use doctests in the canonical form (tests inside the function docstring)
  with extreme moderation, because I don't like gigantic docstrings;

2. I use doctests in the module-level docstring *a lot*;

3. I put doctests which are more tests than doc in a separate
  text file, so they don't bother the reader of the code.

The best solution, IMO, is to do literate programming: I have a hand made
utility that extracts the docstrings from a module (or sets of modules) and
i) generate a nice looking PDF documentation; ii) run all the tests contained
in the documentation.

In theory, doctests allows you to insert text in your code: but I have
perverted them enough that now I just insert the code in my text. This
is the literate programming way, and I like it very much. For a concrete
example, you can look at the documentation of my decorator module
(http://www.phyast.pitt.edu/~micheles/python/documentation.html).

I must add that I have completely removed all my unittests. I prefer very
much to put my tests in the documentation, so that I am sure that the
documentation is always updated. I often write support code to make my
doctest look nicer.

Using s-expr based doctests may be fine, but it goes in a completely
different direction than literate programming.

Having said that, a couple of years ago I did some experiment with
a doctest-inspired testing framework. Here is some code which was
sitting on my hard disk:

(use srfi-1 miscmacros)

(define *test-count* 0)
(define *fail-count* 0)

;; a saner try-except statement, introduces a binding for exn
(define-macro (try expr . error-management)
 `(handle-exceptions exn (begin ,@error-management) ,expr))

;; convert a condition into an error string
(define (format-exn exn)
 (define loc (or ((condition-property-accessor 'exn 'location) exn) ))
 (define msg ((condition-property-accessor 'exn 'message) exn))
 (define arguments ((condition-property-accessor 'exn 'arguments) exn))
 (define args (if (null? arguments)  (str-drop arguments 1 1)))
 (sprintf Error: (~a~a) ~a loc args msg))

;; a nice looking assert macro for doctesting
(define-macro ( . body)
 (let ((got (gensym)) (exp (gensym)))
 `(begin
(define ,exp ,(last body))
(define ,got (try (begin ,@(butlast body)) (format-exn exn)))
(inc! *test-count*)
(unless (equal? ,got ,exp)
(inc! *fail-count*)
(printf FAIL: test #~a, got ~a\nexpected ~a\n
*test-count* ,got ,exp)

(define (show-test-results)
 (printf ~a tests, ~a ok, ~a fail\n
 *test-count* (- *test-count* *fail-count*) *fail-count*))

;; example
( (+ 1 1)
   2)

That's all,

Michele Simionato


___
Chicken-users mailing list
Chicken-users@nongnu.org
http://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] postgresql update

2006-11-29 Thread Michele Simionato

The trivial tests work on my system. BTW, I just installed chicken 2.5 from
scratch on this machine and tried to download postgresql. I got

downloading postgresql.egg from
(www.call-with-current-continuation.org eggs 80) .
 gunzip -c ../postgresql.egg | tar xf -
 /usr/local/bin/csc -feature compiling-extension -s -R syntax-case
-O2 -d0 postgresql.scm -C -I`pg_config --includedir` -L -L`pg_config
--libdir` -lpq
Warning: extension `syntax-case' is currently not installed
Syntax error: define-syntax
highlevel macros are not supported

Since the error message was pretty clear, I installed `syntax-case' and tried
again to install postgresql, without problem this time. But I wonder if this
is okay, or if chicken-setup is supposed to install all the required
dependencies
automatically. What are the future plans for chicken-setup and eggs in general,
with respect of management of (inter)dependencies?

Michele Simionato


___
Chicken-users mailing list
Chicken-users@nongnu.org
http://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] A few questions...

2005-08-19 Thread Michele Simionato
On 8/17/05, felix winkelmann [EMAIL PROTECTED] wrote:
 
 Q3: What are you missing most desperately from Chicken, or better:
   if there is one thing that you really want it to have, what would that be?

I wanted two things, better debugging and a nice module system. I am still
evaluating van Tonder's system, it looks fine (BTW, I discovered a subtility:
if you define a macro which name ends with : you get a syntax error; I
guess this is due to some confusion with the keyword syntax; strangely
enough there no such a problem with low-level macros). So, better debugging
is my last wish ;)

  Michele Simionato


___
Chicken-users mailing list
Chicken-users@nongnu.org
http://lists.nongnu.org/mailman/listinfo/chicken-users


[Chicken-users] Re: first experiments with simple-macros

2005-08-04 Thread Michele Simionato
Felix:

 The toplevel has by default the scheme and chicken modules
 imported. The chicken module exports everything that is provided
 by the library and eval library units. To use stuff from extras, say:
 
 (use (module extras))
 (import extras)
 
 [Note the separation of loading/linking and import]

Thanks, this answered my next question ;)

 Hm. ,x Works for me. What output do you get?

I take back what I said. I cannot reproduce the problem. Who knows
what happened, anyway now it seems to be okay.

 Keep in mind that this is really quite experimental (it isn't officially
 announced yet). We are working on the bleeding edge here... ;-)

Yes, this is why I waited some time before trying it, to have things
settled down for me ;) I read the first announcement on c.l.s. a while ago 
and I thought it was too good to be true. What I like the most is the 
module system, I have yet to test it seriously, but at least the
description in the SRFI document makes sense and it is more or less
what I had desired for a module system for my first day in Scheme
(I remember at that time I escaped from the Mzscheme module system
which I felt overcomplicated; I also hated the fact that it forced me 
to write macro definitions and helper functions in separate modules,
for reasons that never convinced me). A thing I have always looked at 
with suspicion in Chicken (suspicion of being more complicated than
needed) is eval-when: OTOH, van Tonder's system works in a pretty 
obvious and reasonable way (by default things are evaluated both
at compile time and import time; if you want to evaluate things
at compile time only you say so and if you want to evaluate things
at import time only you say so: the quintessence of semplicity). 
Still I do not understand why things should be more complicated 
than that and which are the pittfalls of van Tonder's system (if any).

I should have some time in the next days to test the module system
more in details and to see how it goes. So expect some other feedback!

P.S. I forgot: thanks for including srfi-72 in Chicken so soon!


___
Chicken-users mailing list
Chicken-users@nongnu.org
http://lists.nongnu.org/mailman/listinfo/chicken-users


[Chicken-users] postgresql egg

2005-08-01 Thread Michele Simionato
I have installed Chicken 2 and tried to reinstall the postgresql egg. However
since the -hygienic option has been removed I get this error:

$ sudo chicken-setup postgresql
  /usr/local/bin/csc -feature compiling-extension -s -hygienic -O2 -d0
postgresql.scm -C -I`pg_config --includedir` -L -L`pg_config --libdir`
-lpq
csc: invalid option `-hygienic'
Error: shell invocation failed with non-zero return status
/usr/local/bin/csc -feature compiling-extension -s -hygienic -O2 -d0
postgresq...
64
Error: shell invocation failed with non-zero return status
/usr/local/bin/csc -feature compiling-extension -s -hygienic -O2 -d0
postgresq...
64


___
Chicken-users mailing list
Chicken-users@nongnu.org
http://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] loading libraries: inconsistencies interpreter vs. compiler

2005-06-14 Thread Michele Simionato
On 6/13/05, felix winkelmann [EMAIL PROTECTED] wrote:
 On 6/12/05, Michele Simionato [EMAIL PROTECTED] wrote:
 Moreover specifying directories with require-extension is not
 allowed (...and will be documented right now. ;-)

Ok, but then it should NOT work in the interpreter! It gives false
hopes and expectations ...
   
Michele


___
Chicken-users mailing list
Chicken-users@nongnu.org
http://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] loading libraries: inconsistencies interpreter vs. compiler

2005-06-12 Thread Michele Simionato
On 6/13/05, felix winkelmann [EMAIL PROTECTED] wrote:
 On 6/12/05, Michele Simionato [EMAIL PROTECTED] wrote:
  I have a library in a subdirectory of CHICKEN_INCLUDE_PATH, say in
  mystuff/mylib. In the interpreter, from any directory I do
 
  (require-extension mystuff/mylib)
 
 
 CHICKEN_INCLUDE_PATH is not intended to be used for
 libraries (eggs), but for include-files (loaded via `include').
 Moreover specifying directories with require-extension is not
 allowed (...and will be documented right now. ;-)
 

But then, how am I supposed to write a package (package=directory
containing various modules and possibily subpackages)?

 Michele Simionato


___
Chicken-users mailing list
Chicken-users@nongnu.org
http://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] how do I send input to an external program line-by-line?

2005-05-31 Thread Michele Simionato
On 5/31/05, Thomas Chust [EMAIL PROTECTED] wrote:

 To set the buffering mode of the pipe, I would try
 (set-buffering-mode! gnuplot-pipe #:line) 

That did the trick! Thanks! :-)

   Michele Simionato


___
Chicken-users mailing list
Chicken-users@nongnu.org
http://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] url-encoded arguments et similia

2005-05-26 Thread Michele Simionato
On 5/26/05, felix winkelmann [EMAIL PROTECTED] wrote:
 That parameter is only bound in the fallback-handler, that is, for special
 requests like .ssp pages.
 Here's a patch for spiffy.scm: snip

Cool! Please make it

 (parameterize ((current-urlencoded-arguments ,args) (current-request ,req))

so that post-var works too. Actually I like a lot this function, which
I have extracted from define-http-resource:

 (define (add-dynamic-resource url thunk)   
   (http:add-resource url
 (lambda (request args)
   (parameterize ((current-urlencoded-arguments args)
  (current-request request))
   (let/cc return
 (let/ respond (http-resource:responder request return)
   (handle-exceptions exn
 (parameterize 
  ([http:error-response-handler (http-resource:error-handler exn)])
  (http:write-error-response 500 Internal Server Error))
(respond (thunk)

Maybe it would be a good idea to expose it directly, would do you think?

 Michele Simionato


___
Chicken-users mailing list
Chicken-users@nongnu.org
http://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] an ode to Spiffy

2005-05-25 Thread Michele Simionato
On 5/25/05, Graham Fawcett [EMAIL PROTECTED] wrote:
 On 5/25/05, Michele Simionato [EMAIL PROTECTED] wrote:
  I think to get a remote REPL is not difficult, but I have serious doubts
  about getting better tracebacks, since I have never seen a Scheme
  implementation with good error reporting :-(
 
  Guido van Rossum says that he will never make Python tail recursive
  since it does not want to lose nice tracebacks. I don't know if it is
  technically
  possible to get both tail recursion and nice tracebacks, and how difficult
  it is.
 
 I feared that might be the case. Still, any tool that could instrument
 my code to provide some kind of this source-snippet is probably the
 problem report would be beneficial. Maybe I need to do some reading
 on Scheme debuggers...

You may start from

# chicken-setup debug

and see how far you can go.

   Michele Simionato


___
Chicken-users mailing list
Chicken-users@nongnu.org
http://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] hash-table with missing keys

2005-05-19 Thread Michele Simionato
On 5/18/05, felix winkelmann [EMAIL PROTECTED] wrote:
 
  -- procedure: hash-table-ref
   (hash-table-ref HASH-TABLE KEY [DEFAULT])
  Returns the entry in the given hash-table under `KEY'. If no entry
  is stored in the table, `DEFAULT' is returned, or `#f' if
  `DEFAULT' is not given.
 
 
 cheers,
 felix

You misunderstood Felix. The question is


what's the rationale for

(hash-table-ref h 'non-existing-key)

returning #f instead of an error? 


Returning #f is ambiguous, it could mean that the key exists with value #f!


 Michele Simionato


___
Chicken-users mailing list
Chicken-users@nongnu.org
http://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] hash-table with missing keys

2005-05-19 Thread Michele Simionato
On 5/19/05, felix winkelmann [EMAIL PROTECTED] wrote:

 the reason why one should use (for example):
 
 (hash-table-ref h 'non-existing-key

 some-unique-value-known-to-the-application-that-created-and-uses-the-hashtable)
 
 to disambiguate the result:
 
 (let ((unique (list 1)))
   (if (eq? unique (hash-table-ref ht 'non-existing-key unique))
   ...not found...
   ...found...))

Yes, this is what I am doing now, but it is ugly, too low-level for my taste.
Felix, I give you an ultimatum: or you raise an exception,
or you give me a hash-table-has-key? function! ;-)

Michele


___
Chicken-users mailing list
Chicken-users@nongnu.org
http://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] hash-table with missing keys

2005-05-19 Thread Michele Simionato
On 5/19/05, felix winkelmann [EMAIL PROTECTED] wrote:
 On 5/19/05, Michele Simionato [EMAIL PROTECTED] wrote:
 
  Yes, this is what I am doing now, but it is ugly, too low-level for my 
  taste.
 
 No, it's perfectly fine... ;-)
 
  Felix, I give you an ultimatum: or you raise an exception,
  or you give me a hash-table-has-key? function! ;-)
 
 
 okok...
 

I am thinking of hash-tables containing booleans, for instance users
with a given permission, and I want to know if the user is in the table or
not. Perhaps the negative version hash-table-missing-key? is more useful
than the positive version hash-table-has-key?, since tipically I want
to raise an error if the key is missing.

 Michele


___
Chicken-users mailing list
Chicken-users@nongnu.org
http://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] match-let and hygiene incompatible?

2005-05-19 Thread Michele Simionato
On 5/19/05, Greg Buchholz [EMAIL PROTECTED] wrote:
 
 Are hygienic macros incompatible with the pattern matching as
 described in...
 
 http://www.call-with-current-continuation.org/manual/Unit-match.html
 
 ...When I use the -hygienic option, I get an error like...
 
 Error: unbound variable: a
 
 ...for this piece of code...
 
 (display (match-let (((a b c) (list 1 2 3)))
 (+ a b c)))
 
 ...Which works perfectly with no hygiene option specified.
 
 
 Thanks,
 
 Greg Buchholz
 

When you use hygienic rules you must (require 'match) explicitely.
I have pointed out the same issue to Felix a while ago, there also
other subtle differences between the two macro systems. You should
browse in the mailing list history for more (or maybe there is already
somewhere a page listing all the differences? if not, I should write one ;)

Michele Simionato


___
Chicken-users mailing list
Chicken-users@nongnu.org
http://lists.nongnu.org/mailman/listinfo/chicken-users