Re: [racket] Metaprogramming with scheme

2010-06-25 Thread Valeriya Pudova


The errortrace library is good but for development time not for this 
case.  Also it does not tell error location for each function anyway. 
Probably because continuation created not for each function.


But I found another interesting thing. The error message in DrRake and 
command line rake are different (I did not know that). And rake's 
messages more informative. That is good news for me.


In the any case the errortrace display more info.



_
 For list-related administrative tasks:
 http://lists.racket-lang.org/listinfo/users


Re: [racket] Metaprogramming with scheme

2010-06-25 Thread Valeriya Pudova



I suppose the errortrace library might give you more location
information. I have never used it so I can't say much more than read
the docs and/or hope someone else replies.

HTH,
N.
   


The errortrace library is good but for development time not for this 
case.  Also it does not tell error location for each function anyway. 
Probably because continuation created not for each function.


But I found another interesting thing. The error message in DrRake and 
command line rake are different (I did not know that). And rake's 
messages more informative. That is good news for me.



_
 For list-related administrative tasks:
 http://lists.racket-lang.org/listinfo/users


Re: [racket] Metaprogramming with scheme

2010-06-23 Thread Noel Welsh
On Wed, Jun 23, 2010 at 1:44 PM, Valeriya Pudova
 wrote:
> Looks not bad. But if error will be at the top level
...
> (+ 1 "2")
>
> Then error message is not informative
>
> +: expects type  as 2nd argument, given: "2"; other arguments were:
> 1
> C:\Racket\collects\racket\private\map.rkt:45:11: for-each
...
>
> It does not reffer to the error location. Can it be solved?

I suppose the errortrace library might give you more location
information. I have never used it so I can't say much more than read
the docs and/or hope someone else replies.

HTH,
N.
_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/users


Re: [racket] Metaprogramming with scheme

2010-06-23 Thread Valeriya Pudova

On 23.06.2010 16:44, Valeriya Pudova wrote:
In case if foo.ss will have (display (foo 1 2)) the error message will be 

should be text:

In case if foo.ss will have (display (foo 1 "2")) the error message will be
_
 For list-related administrative tasks:
 http://lists.racket-lang.org/listinfo/users


Re: [racket] Metaprogramming with scheme

2010-06-23 Thread Valeriya Pudova

I want share the my current test code. But this code have one issue.



(define-syntax (baz stx)
  (syntax-case stx ()
((_ a b) #'(* a b

(define (bar a b)
  (list (+ a b)))

(define (foo a b)
  (car (bar a b)))

(display (foo 1 2)) ;; can be (foo 1 "2") to produce exception
(display (baz 12 22))





#lang scheme

(define-namespace-anchor a)
(define ns (namespace-anchor->namespace a))

(define (file->syntax file-name)
  ;; read the file and convert it to the syntax object
  (let* ([in (open-input-file file-name)])
(port-count-lines! in)
(begin0
  (let loop ([rs '()]
 [r (read-syntax file-name in)])
(if (eof-object? r)
(reverse rs)
(loop (cons r rs) (read-syntax file-name in
  (close-input-port in)
)))

(with-input-from-file "foo.ss"
 (lambda ()
   (parameterize ([error-display-handler (lambda (name . stuff)
   (begin
   (printf "~a\n" name)
   (for-each (lambda (e)

   (printf 
"~a:~a:~a: ~a\n"
   
(srcloc-source (cdr e))
   
(srcloc-line (cdr e))
   
(srcloc-column (cdr e))

   (car e))
   ) 
(continuation-mark-set->context (exn-continuation-marks  (car stuff

   ))])
 (for-each (lambda (e) (eval e ns)) (file->syntax "foo.ss")



In case if foo.ss will have (display (foo 1 2)) the error message will be

+: expects type  as 2nd argument, given: "2"; other arguments 
were: 1

foo.ss:6:0: bar
foo.ss:9:0: foo
C:\Racket\collects\racket\private\map.rkt:45:11: for-each
C:\Racket\test.ss:#f:#f: [running body]
C:\Racket\collects\racket\private\more-scheme.rkt:274:2: 
call-with-exception-handler

 etc

Looks not bad. But if error will be at the top level


;(display (foo 1 2))
;(display (baz 12 22))
(+ 1 "2")

Then error message is not informative

+: expects type  as 2nd argument, given: "2"; other arguments 
were: 1

C:\Racket\collects\racket\private\map.rkt:45:11: for-each
C:\Racket\test.ss:#f:#f: [running body]
 etc

It does not reffer to the error location. Can it be solved?


_
 For list-related administrative tasks:
 http://lists.racket-lang.org/listinfo/users


Re: [racket] Metaprogramming with scheme

2010-06-23 Thread Valeriya Pudova

On 23.06.2010 14:13, Noel Welsh wrote:

On Wed, Jun 23, 2010 at 5:39 AM, Valeriya Pudova
  wrote:
   

Last quoestion. Is there any way  to define error-display-handler to
printout the back trace even if there are default exception case?
 

I think I don't understand the question. Every exception contains
continuations marks, so it should be straightforward to write your own
error-display-handler to printout the trace. Does this help?

N.
   

Oh!
Guess I found the answer

[error-display-handler (lambda (name . stuff)
   (for-each (lambda (e) (display e)(newline)) 
(continuation-mark-set->context (exn-continuation-marks  (car stuff

)]

Thank You
_
 For list-related administrative tasks:
 http://lists.racket-lang.org/listinfo/users


Re: [racket] Metaprogramming with scheme

2010-06-23 Thread Noel Welsh
On Wed, Jun 23, 2010 at 5:39 AM, Valeriya Pudova
 wrote:
> Last quoestion. Is there any way  to define error-display-handler to
> printout the back trace even if there are default exception case?

I think I don't understand the question. Every exception contains
continuations marks, so it should be straightforward to write your own
error-display-handler to printout the trace. Does this help?

N.
_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/users


Re: [racket] Metaprogramming with scheme

2010-06-22 Thread Valeriya Pudova



> (with-input-from-file "foo.ss"
> (lambda ()
>(parameterize ([error-display-handler (lambda (name . stuff)
> (printf "Got ~a ~a\n" name stuff))])
>  (eval-syntax (read-syntax 'foo.ss)


Last quoestion. Is there any way  to define error-display-handler to 
printout the back trace even if there are default exception case?


(define (foo a b) (+ a b))
(+ a1 "2")
=> producece exception and error-display-handler extract and print the 
back trace


-
Val.
_
 For list-related administrative tasks:
 http://lists.racket-lang.org/listinfo/users


Re: [racket] Metaprogramming with scheme

2010-06-22 Thread Valeriya Pudova

On 22.06.2010 11:34, Eli Barzilay wrote:

(define (foo3 x)
  (/ x "1"))

   (define (foo2 x)
 (foo3 x))
(define (foo1 x)
  (list (foo2 x)))
   (define (foo0 x)
 (car (foo1 x)))

(+ 1 (foo0 3))
   

Oh. Right. Thanks allot.
_
 For list-related administrative tasks:
 http://lists.racket-lang.org/listinfo/users


Re: [racket] Metaprogramming with scheme

2010-06-22 Thread Eli Barzilay
On Jun 22, Valeriya Pudova wrote:
> 
> (define (foo a b)
>(for-each (lambda (e) (display e)(newline)) 
> (continuation-mark-set->context (current-continuation-marks
> 
> (define (bar a b)
>(foo a b))
> 
> (bar 1 2)
> [...]
> 
> Interesting. There are no the function bar in the backtrace. Why?

Because it's no longer there -- the tail call replaces it.  Try to run
this in DrRacket (exactly as is, don't reindent):

   (define (foo3 x)
 (/ x "1"))

  (define (foo2 x)
(foo3 x))
   (define (foo1 x)
 (list (foo2 x)))
  (define (foo0 x)
(car (foo1 x)))

   (+ 1 (foo0 3))

and you'll see that the arrows skip `foo2'.

-- 
  ((lambda (x) (x x)) (lambda (x) (x x)))  Eli Barzilay:
http://barzilay.org/   Maze is Life!
_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/users


Re: [racket] Metaprogramming with scheme

2010-06-22 Thread Valeriya Pudova



The continuation marks included in the exception are effectively a
stack trace, and you can convert them into locations. See the docs.

   

:) Reading about continuation marks.


Great feature those continuation marks. But does not looks helpful this 
case.

To be able to get mark i should set it before. Is it not?
_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/users

Re: [racket] Metaprogramming with scheme

2010-06-22 Thread Noel Welsh
On Mon, Jun 21, 2010 at 4:25 PM, Valeriya Pudova
 wrote:
> That the problem. The location will be location inside foo but not location
> where foo was called from

The continuation marks included in the exception are effectively a
stack trace, and you can convert them into locations. See the docs.

That said, as I recall your initial post was about macro expansion --
for which Robby's post is relevant. If you just want to expand the
macros the function 'expand' (and related functions) are what you
want.

N.
_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/users


Re: [racket] Metaprogramming with scheme

2010-06-22 Thread Valeriya Pudova

On 22.06.2010 10:40, Valeriya Pudova wrote:



The continuation marks included in the exception are effectively a
stack trace, and you can convert them into locations. See the docs.

   

:) Reading about continuation marks.


Great feature those continuation marks. But does not looks helpful 
this case.

To be able to get mark i should set it before. Is it not?


Wow!

(define (foo a b)
  (for-each (lambda (e) (display e)(newline)) 
(continuation-mark-set->context (current-continuation-marks


(define (bar a b)
  (foo a b))

(bar 1 2)

=>
(foo . #(struct:srcloc c:\documents and settings\v\desktop\test.ss 2 0 2 
127))
(call-with-exception-handler . #(struct:srcloc 
C:\Racket\collects\racket\private\more-scheme.rkt 274 2 9287 256))
(loop . #(struct:srcloc C:\Racket\collects\drracket\private\rep.rkt 1134 
19 47088 797))
(call-with-break-parameterization . #(struct:srcloc 
C:\Racket\collects\racket\private\more-scheme.rkt 158 2 5099 519))
(#f . #(struct:srcloc C:\Racket\collects\drracket\private\rep.rkt 1115 9 
46083 2670))
(loop . #(struct:srcloc C:\Racket\collects\drracket\private\rep.rkt 1375 
17 58510 808))


Interesting. There are no the function bar in the backtrace. Why?
_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/users

Re: [racket] Metaprogramming with scheme

2010-06-22 Thread Valeriya Pudova

On 22.06.2010 9:31, Noel Welsh wrote:

On Mon, Jun 21, 2010 at 4:25 PM, Valeriya Pudova
  wrote:
   

>  That the problem. The location will be location inside foo but not location
>  where foo was called from
 

The continuation marks included in the exception are effectively a
stack trace, and you can convert them into locations. See the docs.

   

:) Reading about continuation marks.

That said, as I recall your initial post was about macro expansion --
for which Robby's post is relevant. If you just want to expand the
macros the function 'expand' (and related functions) are what you
want.

   

Right. But now only macro expansion also expressions evaluation.
Well, lets hope that "continuation marks"  are help to get a backtrace 
that may help.
_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/users

Re: [racket] Metaprogramming with scheme

2010-06-21 Thread Robby Findler
Actually it does but it is diasabled by default. But the point was
that you would not do it that way but instead use the lang and macro
system to implement your translation.

Robby

On Monday, June 21, 2010, Valeriya Pudova  wrote:
> On 21.06.2010 18:32, Robby Findler wrote:
>
> I haven't followed this thread too closely but if you can tolerate
> your "a.ss" file having a "#lang" line at the top that may make your
> life overall much easier (the Racket tools all work better when you
> are explicit about the language you are programming in).
>
> Robby
>
>
>
> The read-syntax does not support #lang :
>
> #lang expressions not currently enabled (#(struct:exn:fail:read read: #lang 
> expressions not currently enabled # (#(struct:srcloc 
> foo.ss #f #f 1 6
>
> _
>  For list-related administrative tasks:
>  http://lists.racket-lang.org/listinfo/users
>
_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/users

Re: [racket] Metaprogramming with scheme

2010-06-21 Thread Valeriya Pudova

On 21.06.2010 18:25, Noel Welsh wrote:

On Mon, Jun 21, 2010 at 2:41 PM, Valeriya Pudova
  wrote:
   

There are two issues.

First:

what if the file foo.ss will have defined function foo.

(define (foo a b) (+ a b)))
(foo 1 2)

It makes error:
Got compile: unbound identifier (and no #%app syntax transformer is bound)
(#(struct:exn:fail:syntax compile: unbound identifier (and no #%app syntax
transformer is bound) #
 

This is a namespace issue. You need to create a namespace (with, e.g.,
(make-base-namespace)) and pass that as the 2nd optional argument to
eval-syntax. See the Guide and Reference for more detail.

   

Yes that helps

Second:
When function foo is defined correctly and called from the eval process and
errors occurs in foo, how can we find the caller's location in order to
format an error message?
 

I think whatever location information is available will be in the exception.

   
That the problem. The location will be location inside foo but not 
location where foo was called from


_
 For list-related administrative tasks:
 http://lists.racket-lang.org/listinfo/users


Re: [racket] Metaprogramming with scheme

2010-06-21 Thread Valeriya Pudova

On 21.06.2010 18:32, Robby Findler wrote:

I haven't followed this thread too closely but if you can tolerate
your "a.ss" file having a "#lang" line at the top that may make your
life overall much easier (the Racket tools all work better when you
are explicit about the language you are programming in).

Robby
   


The read-syntax does not support #lang :

#lang expressions not currently enabled (#(struct:exn:fail:read read: 
#lang expressions not currently enabled # 
(#(struct:srcloc foo.ss #f #f 1 6


_
 For list-related administrative tasks:
 http://lists.racket-lang.org/listinfo/users


Re: [racket] Metaprogramming with scheme

2010-06-21 Thread Robby Findler
I haven't followed this thread too closely but if you can tolerate
your "a.ss" file having a "#lang" line at the top that may make your
life overall much easier (the Racket tools all work better when you
are explicit about the language you are programming in).

Robby
_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/users


Re: [racket] Metaprogramming with scheme

2010-06-21 Thread Noel Welsh
On Mon, Jun 21, 2010 at 2:41 PM, Valeriya Pudova
 wrote:
> There are two issues.
>
> First:
>
> what if the file foo.ss will have defined function foo.
>
> (define (foo a b) (+ a b)))
> (foo 1 2)
>
> It makes error:
> Got compile: unbound identifier (and no #%app syntax transformer is bound)
> (#(struct:exn:fail:syntax compile: unbound identifier (and no #%app syntax
> transformer is bound) #

This is a namespace issue. You need to create a namespace (with, e.g.,
(make-base-namespace)) and pass that as the 2nd optional argument to
eval-syntax. See the Guide and Reference for more detail.

> Second:
> When function foo is defined correctly and called from the eval process and
> errors occurs in foo, how can we find the caller's location in order to
> format an error message?

I think whatever location information is available will be in the exception.

N.
_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/users


Re: [racket] Metaprogramming with scheme

2010-06-21 Thread Valeriya Pudova
> > name space
> > where are defined methods "define-fsm", "define-state", "on-event" and
> "go"
> >
> > But this case each of those methods will not have the syntax object of
> the
> > evaluated expression.
> > And in case if it will find and error it could not message about error's
> > location. The easiest way to do this task can be: Just evaluate the file
> "a.ss" in the
>

Noel Welsh wrote:

> Have you tried eval-syntax, instead of eval? I think that will keep
> location information.
>


How?

(eval-syntax (file->syntax "a.ss"))

lets imagine the function 'define-fsm' was called. And "some-condition?"
informs that there are syntax error in the source expression. How i can
printout the line and column number of the source expression?

(define (define-fsm params)
  (if (some-condition? params)
 (display "error message" ? )
  )
)

Noel Welsh  wrote:
> Look up read-syntax.

Yes, In my example file->syntax was somthing like

(define (file->syntax file-name)
  ;; read the file and convert it to the syntax object
  (let* ([in (open-input-file file-name)])
(port-count-lines! in)
(begin0
  (let loop ([rs '()]
 [r (read-syntax file-name in)])
(if (eof-object? r)
(reverse rs)
(loop (cons r rs) (read-syntax file-name in
  (close-input-port in)
)))

Noel Welsh  wrote:
> lets imagine the function 'define-fsm' was called. And "some-condition?"
> informs that there are syntax error in the source expression. How i can
> printout the line and column number of the source expression?

> http://docs.racket-lang.org/unstable/Source_Locations.html


The question is: when in the eval-synax process there will be called some
function how that function can to reffer to the current syntax-object?

Noel Welsh wrote:
> foo.ss:

> (foo 1 2)

> Code:

> (with-input-from-file "foo.ss"
> (lambda ()
>(parameterize ([error-display-handler (lambda (name . stuff)
> (printf "Got ~a ~a\n" name stuff))])
>  (eval-syntax (read-syntax 'foo.ss)

> Output:

> Got foo.ss::0: compile: unbound identifier (and no #%app syntax
> transformer is bound) at: foo in: (foo 1 2) (#(struct:exn:fail:syntax
> foo.ss::0: compile: unbound identifier (and no #%app syntax
> transformer is bound) at: foo in: (foo 1 2) #
> (#)))

> So the exception structure has the syntax object you want.

There are two issues.

First:

what if the file foo.ss will have defined function foo.

(define (foo a b) (+ a b)))
(foo 1 2)

It makes error:
Got compile: unbound identifier (and no #%app syntax transformer is bound)
(#(struct:exn:fail:syntax compile: unbound identifier (and no #%app syntax
transformer is bound) #

Second:
When function foo is defined correctly and called from the eval process and
errors occurs in foo, how can we find the caller's location in order to
format an error message?


-- Valeriya
_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/users

Re: [racket] Metaprogramming with scheme

2010-06-21 Thread Noel Welsh
Please reply to the list; you'll get more help that way. (Also, I'll
ignore your emails if you don't.)

On Mon, Jun 21, 2010 at 12:29 PM, Valeriya Pudova
 wrote:
> The question is: when in the eval-synax process there will be called some
> function how that function can to reffer to the current syntax-object?

foo.ss:

(foo 1 2)

Code:

(with-input-from-file "foo.ss"
  (lambda ()
(parameterize ([error-display-handler (lambda (name . stuff)
(printf "Got ~a ~a\n" name stuff))])
  (eval-syntax (read-syntax 'foo.ss)

Output:

Got foo.ss::0: compile: unbound identifier (and no #%app syntax
transformer is bound) at: foo in: (foo 1 2) (#(struct:exn:fail:syntax
foo.ss::0: compile: unbound identifier (and no #%app syntax
transformer is bound) at: foo in: (foo 1 2) #
(#)))

So the exception structure has the syntax object you want.

N.
_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/users


Re: [racket] Metaprogramming with scheme

2010-06-21 Thread Noel Welsh
Please reply to the list; you'll get more help that way.

On Mon, Jun 21, 2010 at 12:14 PM, Valeriya Pudova
 wrote:
> (eval-syntax (file->syntax "a.ss"))

Look up read-syntax.

> lets imagine the function 'define-fsm' was called. And "some-condition?"
> informs that there are syntax error in the source expression. How i can
> printout the line and column number of the source expression?

http://docs.racket-lang.org/unstable/Source_Locations.html

N.
_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/users


Re: [racket] Metaprogramming with scheme

2010-06-21 Thread Noel Welsh
On Sat, Jun 19, 2010 at 10:00 AM, Valeriya Pudova
 wrote:
> The easiest way to do this task can be: Just evaluate the file "a.ss" in the
> name space
> where are defined methods "define-fsm", "define-state", "on-event" and "go"
>
> But this case each of those methods will not have the syntax object of the
> evaluated expression.
> And in case if it will find and error it could not message about error's
> location.

Have you tried eval-syntax, instead of eval? I think that will keep
location information.

HTH,
N.
_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/users