Re: [racket-users] Writing a "command-line front-end" for a language

2022-09-04 Thread Shu-Hung You
On Sun, Sep 4, 2022 at 4:21 AM Reuben Thomas  wrote:
>
> On Sat, 3 Sept 2022 at 19:10, Shu-Hung You  wrote:
>>
>> Running `racket foo.asm` will produce the desired output, so a shell
>> script that directly passes the arguments to Racket could work.
>> Otherwise, just use (dynamic-require filename #f) in main.rkt.
>
>
> Thanks for helping!
>
> Don't both of these methods require a #lang line in the input file? That's 
> not part of the assembly format, so I want to be able to specify the language 
> in the main module. Indeed, when I try it with a file with a #lang line, 
> dynamic-require works; when I remove that line, I get an error about a 
> missing module declaration (no surprise). I can see an obvious workaround, 
> namely to slurp the file and prepend a module declaration before 
> dynamic-requiring it, but that's ugly.
>
> So it seems that in fact what I want is to call something like 
> dynamic-require with a module object. But I'm not sure what to call or how to 
> get one of those: read-syntax returns a syntax object, not a module, while I 
> don't (yet) know how to apply my expander's #%module-begin to it to obtain a 
> module.
>

Okay, if you want to bypass the #lang protocol entirely, here is the
needed code. As you have expected, it uses eval and then calls
dynamic-require.

diff --git a/asm.rkt b/asm.rkt
index f2f1e89..4d024d8 100644
--- a/asm.rkt
+++ b/asm.rkt
@@ -6,6 +6,7 @@

 (define (read-syntax path port)
   (define parse-tree (parse path (make-tokenizer port path)))
-  (strip-bindings
-   #`(module hackasm-mod hackasm/expander
-   #,parse-tree)))
+  (datum->syntax
+   #f
+   `(,#'module hackasm-mod hackasm/expander
+  ,parse-tree)))
diff --git a/main.rkt b/main.rkt
index 9f2af0b..9cccf22 100644
--- a/main.rkt
+++ b/main.rkt
@@ -8,4 +8,6 @@
   #:program "hackasm" ; FIXME: get name from project
   #:args (filename)
   filename)))
-(dynamic-require filename #f)))
\ No newline at end of file
+(parameterize ([current-namespace (make-base-empty-namespace)])
+  (eval (read-syntax filename (open-input-file filename)))
+  (dynamic-require '(quote hackasm-mod) #f

There are two technical details. The eval function takes pretty much
everything --- plain values, syntax objects, or just S-expressions,
etc. For eval, the difference between syntax objects and S-expressions
is that syntax objects carry binding information with them, therefore
eval can correctly run the code without the risk of misinterpreting
identifiers. The syntax object that your read-syntax returns is almost
runnable, so I use eval to evaluate the resulting module form (i.e.
#'(module hackasm-mod hackasm/expander ...)). This will declare a
module called ‘hackasm-mod’ together with its code in the current
namespace's module registry. Subsequently, dynamic-require
instantiates the module ‘hackasm-mod’ to run its body. The reference
https://docs.racket-lang.org/reference/module.html#%28form._%28%28quote._~23~25kernel%29._module%29%29
specifies what evaluating a module form results in (search for
"evaluation"). In dynamic-require, the module path (quote hackasm-mod)
refers to the module declared with the name ‘hackasm-mod’. In the more
common cases, module paths would be complete file paths. The page
https://docs.racket-lang.org/guide/module-paths.html explains the
syntax of module paths.

In the original read-syntax, I suppose strip-bindings removes all
binding information associated with the given syntax objects.
Consequently, eval would fail to interpret the resulting module form
because the "module" identifier in it is unbound and thus has no
meaning. To fix the issue, I explicitly use the #'module identifier
found in asm.rkt (which is the Racket binding of ‘module’, brought
into context by #lang br/quicklang). Then datum->syntax turns the
entire list into a syntax object with no binding information.
Equivalently, instead of changing read-syntax you can manually fix the
#'module identifier before `eval` using the low-level APIs syntax-e
and datum->syntax.

>> At the technical level, foo.asm is in fact an ordinary Racket module,
>> just like any other .rkt file. Therefore it can be run in the same way
>> using APIs that require and instantiate modules.
>
>
> Right! That's what I've obviously not fully understood yet.
>
> (Thanks for the side node about moving to Discourse—it's a while since I've 
> been active on the list!)
>
> --
> https://rrt.sc3d.org

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAMTzy%2BavnPCDvR8wHN3O_9BgnpQK%2BtamD9PqmBwd%2B9j-YGHUqg%40mail.gmail.com.


Fwd: [racket-users] Writing a "command-line front-end" for a language

2022-09-03 Thread Shu-Hung You
-- Forwarded message -
From: Shu-Hung You 
Date: Sat, Sep 3, 2022 at 1:03 PM
Subject: Re: [racket-users] Writing a "command-line front-end" for a language
To: Reuben Thomas 


Running `racket foo.asm` will produce the desired output, so a shell
script that directly passes the arguments to Racket could work.
Otherwise, just use (dynamic-require filename #f) in main.rkt.

At the technical level, foo.asm is in fact an ordinary Racket module,
just like any other .rkt file. Therefore it can be run in the same way
using APIs that require and instantiate modules.

---

On a side note, the forum has mostly moved to Discourse
(https://racket.discourse.group/).

On Sat, Sep 3, 2022 at 6:01 AM 'Reuben Thomas' via Racket Users
 wrote:
>
> I'm a relative Racket newbie, and I've just enjoyed Beautiful Racket.
>
> I am working on a Racket implementation of a simple assembler (for the Hack 
> VM in the NAND2Tetris course).
>
> I have a partial implementation up and running using #lang lines. I would 
> like to add a more traditional command-line interface, so I can (eventually) 
> say:
>
> hackasm foo.asm
>
> on a file without a #lang line.
>
> My code is available at https://github.com/rrthomas/hackasm
>
> Here's the nub of the problem: I can't work out how to call the language 
> evaluator "manually". I have implemented the language as a dialect, so that 
> the "main.rkt" module is "free" to be used for the command-line interface. 
> (Perhaps this can be fixed too, that would be nice!)
>
> A typical assembler file might start like this:
>
> #lang hackasm/asm
> @2
> D=A
> @3
>
> When I run this file (e.g. in DrRacket), I get some output as expected:
>
> 0010
> 11101101
> 0011
>
> (The assembler outputs ASCII-encoded binary!)
>
> The contents of my main.rkt looks like this:
>
> #lang br/quicklang
> (require "parser.rkt" "tokenizer.rkt" (submod "asm.rkt" reader))
>
> (module+ main
>   (require racket/cmdline)
>   (let ((filename
>  (command-line
>   #:program "hackasm" ;
>   #:args (filename)
>   filename)))
> (read-syntax filename (open-input-file filename
>
> So far, all I've worked out how to do is run the language's read-syntax 
> function (imported from parser.rkt), and thereby return the parsed syntax 
> object as the result.
>
> What I'd like to do is call the evaluator on the parse tree, but after a lot 
> of scratching my head over the Racket documentation and search results, I 
> cannot work out how to do that. I presume the code should look something like:
>
> (eval (??? (read-syntax filename (open-input-file filename
>
> where in the end I'm eval-ing a form, and where ??? represents something that 
> turns the syntax object into a runnable module.
>
> Apologies for the length of this post (I was unsure how I could make it 
> shorter), and thanks in advance for any help!
>
> --
> https://rrt.sc3d.org
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/racket-users/CAOnWdohy31fHyvUd9rbY8tZFLJKUpevgnZ8jPH2-5_QtSFm%2BhA%40mail.gmail.com.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAMTzy%2BYSy2DH3zzdpzujRuiu37zMzKYZvu0p%2Bfk1RsNqeuJRDQ%40mail.gmail.com.


Re: [racket-users] Find the source location of the syntax error in DrRacket

2021-08-14 Thread Shu-Hung You
Cool! I thought the existing syntax/loc have already put the correct
source location on the output of the macro, but the inner let is
taking over the stack frame.

On Sat, Aug 14, 2021 at 12:49 AM Sorawee Porncharoenwase
 wrote:
>
> Isn’t that a matter of putting more syntax/loc? I tried:
>
> (-define-syntax let-syntaxes
> (lambda (stx)
>   (syntax-case stx ()
> [(_ ([(id ...) expr] ...) body1 body ...)
>  (with-syntax ([((tmp ...) ...)
> (map
>  generate-temporaries
>  (syntax->list (syntax ((id ...) ...])
>(with-syntax ([inner-body
>   (syntax/loc stx
> (letrec-syntaxes+values
> ([(id ...)
>   (values
>(make-rename-transformer (quote-syntax tmp))
>...)] ...)
> ()
>   body1 body ...))])
>  (syntax/loc stx
>(letrec-syntaxes+values ([(tmp ...) expr] ...) ()
>  inner-body])))
>
> and the button now functions as you expect.
>
>
> On Fri, Aug 13, 2021 at 7:45 PM Shu-Hung You  
> wrote:
>>
>> Here are two syntax errors that behave differently in DrRacket:
>>
>> #lang racket
>>
>> (define-syntax (m-late stx)
>>   #'(let () (define x 0)))
>> (define-syntax (m-early stx)
>>   #'(let-syntax () (define x 0)))
>>
>> ; (m-late)
>> ; (m-early)
>>
>> DrRacket *correctly* highlights the source location of the errors in
>> both cases. Additionally, for (m-early) I can click on the X button to
>> jump to the error location.
>>
>> However, for (m-late) the X button brings me to internal Racket code.
>> What's going on here?
>>
>> In case it helps, here are the error messages when I run the code in 
>> terminal:
>>
>> ;; m-late
>> errstx.rkt:4:4: begin (possibly implicit): no expression after a
>> sequence of internal definitions
>>   in: (begin (define x 0))
>>   location...:
>>/Volumes/ramdisk/errstx.rkt:4:4
>>/Volumes/ramdisk/errstx.rkt:4:12
>>
>> ;; m-early
>> /racket/private/letstx-scheme.rkt:38:17: begin (possibly
>> implicit): no expression after a sequence of internal definitions
>>   in: (begin (define x 0))
>>   location...:
>>/racket/private/letstx-scheme.rkt:38:17
>>/Volumes/ramdisk/errstx.rkt:6:19
>>
>> --
>> You received this message because you are subscribed to the Google Groups 
>> "Racket Users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to racket-users+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/racket-users/CAMTzy%2BZtpWGdtkZkvzF4%3D25kpqUqGKsBcCDf4T%3DY3S2hV0v_GA%40mail.gmail.com.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAMTzy%2BY%3DgzoDviM5q8OhSsUcJnDUSxfnAVc7uZv2ZR97ckOnXA%40mail.gmail.com.


[racket-users] Find the source location of the syntax error in DrRacket

2021-08-13 Thread Shu-Hung You
Here are two syntax errors that behave differently in DrRacket:

#lang racket

(define-syntax (m-late stx)
  #'(let () (define x 0)))
(define-syntax (m-early stx)
  #'(let-syntax () (define x 0)))

; (m-late)
; (m-early)

DrRacket *correctly* highlights the source location of the errors in
both cases. Additionally, for (m-early) I can click on the X button to
jump to the error location.

However, for (m-late) the X button brings me to internal Racket code.
What's going on here?

In case it helps, here are the error messages when I run the code in terminal:

;; m-late
errstx.rkt:4:4: begin (possibly implicit): no expression after a
sequence of internal definitions
  in: (begin (define x 0))
  location...:
   /Volumes/ramdisk/errstx.rkt:4:4
   /Volumes/ramdisk/errstx.rkt:4:12

;; m-early
/racket/private/letstx-scheme.rkt:38:17: begin (possibly
implicit): no expression after a sequence of internal definitions
  in: (begin (define x 0))
  location...:
   /racket/private/letstx-scheme.rkt:38:17
   /Volumes/ramdisk/errstx.rkt:6:19

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAMTzy%2BZtpWGdtkZkvzF4%3D25kpqUqGKsBcCDf4T%3DY3S2hV0v_GA%40mail.gmail.com.


Re: [racket-users] Equivalent of exec

2021-08-03 Thread Shu-Hung You
On Tue, Aug 3, 2021 at 1:13 PM George Neuner  wrote:
>
>
> On 8/3/2021 1:03 PM, Norman Gray wrote:
> > On 3 Aug 2021, at 17:38, George Neuner wrote:
> >
> >> Racket is multi-platform and tries to present a common API for
> >> dealing with underlying operating systems.  Windows is an important
> >> platform, but Windows does not have the concept of fork/exec ... so
> >> Racket doesn't offer it either.
> >
> > Ah: good point.  That said, I'd have guessed that similar behaviour --
> > 'invoke and don't return' -- would be at least emulatable on Windows,
> > though.
>
> Well, yes, but the behavior of  'CreateProcess'  is quite different from
> the combination of  'forkv/execv'.
>
> In Windows, the new child is not (even virtually) a copy of its parent -
> it is a completely new process context.  Although it is possible for the
> parent to pass to and/or share resources with the child, this doesn't
> include a copy of its memory context [so no 'fork'].  The parent
> receives several handles to the new child process that must explicitly
> be closed in order to detach it.
>
> As a technical matter, emulating Unix 'fork' in Windows ... i.e. making
> an independent copy of the parent process that continues running from
> where the parent stopped ... is possible, but it is difficult and
> requires debugger like behavior to manipulate the child's memory map and
> copy data from one process to the other.
>
>
> >> The closest (and simplest) you can achieve, I think, would to start
> >> Vi asynchronously using 'process*' and then terminate the Racket script.
> >
> > I don't think that works, since terminating the Racket process would
> > also terminate its child (unless I were to do something similar to the
> > usual extra fork to disconnect the child from its parent, and... hmmm,
> > this isn't sounding very rackety).
> >
> > Doing the next simplest thing -- using (process* "/usr/bin/vi"
> > '("foo")) and calling (control 'wait) using the result -- doesn't seem
> > to work, but instead just hangs, until I kill the vi child process.
> > Without digging into it too deeply, I'd guess that's because of the
> > usual problems about wiring up FDs and buffers and so on, which I was
> > rather hoping to avoid.
> >
>
> Hmm.  According to the docs  'process'  (no asterisk) executes the
> command asynchronously ... I assumed  'process*' would do the same.
> Unfortunately 'process' returns ports that must be closed explicitly.
>
> Sorry if I led you astray.
>

I tried directly passing the current input port and the current output
port in Racket to the subprocess. As long as they are the original
standard input and the standard output ports, the program seems to
work.

*However*, I am not sure if Racket's runtime still manages the input
and the output.

#lang racket/base

(require racket/match
 racket/system)

(match-define (list subprocess-stdout subprocess-stdin system-pid
subprocess-stderr procctl)
  (process*/ports (current-output-port) (current-input-port)
(current-error-port)
  "/usr/bin/vim"))

(procctl 'wait)

The following variant prevents Racket from terminating the spawn
subprocess. Sadly, it did not work when I changed sh to vim. The error
message from vim was 'Vim: Error reading input, exiting...'.

#lang racket/base

(require racket/match
 racket/system)

(match-define (list subprocess-stdout subprocess-stdin system-pid
subprocess-stderr procctl)
  (parameterize ([current-subprocess-custodian-mode #f])
(process*/ports (current-output-port) (current-input-port)
(current-error-port)
"/bin/sh"
"-c"
"echo sh sleeping; sleep 5; echo sh alive and well")))

(displayln "leave racket")



>
> > Best wishes,
> >
> > Norman
>
> George
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/racket-users/720fc753-7972-b8c1-76ec-4d2a65a763f2%40comcast.net.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAMTzy%2BYdHfw718MkhW7MRTtgSyKZ1rgPrWZD%2B47bXS%2B2JGzFLQ%40mail.gmail.com.


Re: [racket-users] Differences between execution in DrRacket and Command Line

2021-07-12 Thread Shu-Hung You
On Fri, Jul 2, 2021 at 10:25 AM Rhazes Spell  wrote:
>
> Hello-
> I have been using Racket for about 18 months for personal projects and 
> teaching. I have been doing all of my work in DrRacket but I wanted to 
> interact with a module that I wrote on the interactive command line this 
> morning. I am getting an error while using the command line that I am not 
> getting in the Dr.Racket Interactions window.
>
> This is the code that runs fine in the Interactions window of DrRacket:
> (input-financial-data) deserializes the data properly and populates the list 
> variable that I am using correctly. The lines of code in the module are:
>
> ...
> (define data (input-financial-data data-file))
> (printf "~a data records read~n" (length data))
> (define closed-trades (filter trade-closed? data))
> ...
>
> On the command line when running:
> $> racket -i
> ...
> > (enter! "year-1-analysis.rkt")
> I get an error while trying to read a file of serialized structs. The error 
> is:
>
> given value instantiates a different structure type with the same name
>   expected: trade?
>   given: (trade #1=(date* 0 0 0 21 04 2017 3 294 #t -25200 0 "PDT") 'PYPL 
> "simInvest" (list (transaction 2978996 #1# "simInvest" 'PYPL 'BOUGHT 30 
> 43.70) (transaction 29556891965 (date* 0 0 0 23 04 2017 3 294 #t -25200 0 
> "PDT") "simInvest" 'PYPL 'B...
>
>
> My question is what are the differences between using a module in DrRacket 
> versus on the command line? Thank you in advance for your assistance.
>
> Cheers,
> r..
>

One difference is that DrRacket works as if you had enter!-ed the file
"year-1-analysis.rkt" from the very beginning and never left the
module or re-required it. However, I don't see how that could trigger
the current issue.

The error message suggests that the module defining the trade
structure has been instantiated multiple times in different
namespaces. It could be that some other operations unintentionally
caused the problem.

> --
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/racket-users/b438252e-ef79-4bfe-ac7b-2f508d3419ddn%40googlegroups.com.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAMTzy%2BaEd9TgpoSLES9A%2BRSSp2tzmVo3C54S0VO%3DpwjMKuVKnQ%40mail.gmail.com.


Re: [racket-users] How to set type signature for recursive lazy list

2021-07-12 Thread Shu-Hung You
On Sun, Jul 11, 2021 at 8:15 PM Kiong-Gē Liāu  wrote:
>
> Hi, in non-typed racket, I can define a generalized Fibonacci sequence
>
> X[n+k] = f(X[n], X[n+1], , X[n+k-1])
>
> using the following code
>
> #lang racket
>
> (require  racket/stream)
>
> (define (gfib f xs)
>   (define (gfib_t xs)
> (stream-cons (last xs) (gfib_t (append (cdr xs) (list (f xs))
>   (stream-append (drop-right xs 1) (gfib_t xs)))
>
> (define (sum xs) (apply + xs))
> ;; Example of a (0, 1) initialized Fibonacci sequence
> (define gfib20 (gfib sum '(0 1 )))
>
> But using typed racket,  the following code
>
> #lang typed/racket
>
> (require pfds/stream)
>
> (define (sum [xs : (Listof Number)] ) (apply + xs))
>
> (define (gfib [f : (-> (Listof Number) Number)]  [xs : (Listof Number)] )
>   (define (gfib_t [ys : (Listof Number)] )

^~~ You can annotate the codomain type of gfib_t here:

  (define (gfib_t [ys : (Listof Number)]) : Your-Codomain-Type
...)

> (stream-cons (last ys) (gfib_t (append (cdr ys) (list (f ys))
>   (stream-append (stream (drop-right xs 1)) (gfib_t xs)))
>
> leads to error message
>
> ; /home/kiong-ge/Programming/Racket/typed_racket_test.rkt:8:11: Type Checker: 
> insufficient type information to typecheck. please add more type annotations
> ;   in: gfib_t
>
> How should I set the type signature in the typed racket in order to get the 
> same result generated non-typed racket code ?
>
> Thanks,
> Kiong-Ge.
>
>
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/racket-users/baa0af81-f7fb-46bf-b508-d35727cbaef2n%40googlegroups.com.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAMTzy%2Baim8oe0C-OZUOQpcqVC6-8%3D0Ji919ht%2B5CX%3DN06RdB7A%40mail.gmail.com.


Re: [racket-users] Inspiration for pict and 2htdp/image ?

2021-07-07 Thread Shu-Hung You
As of pict, from the slideshow paper I think the answer is yes and
also many other prior works:

https://users.cs.northwestern.edu/~robby/pubs/papers/icfp2004-ff.pdf

> 6 Slideshow Design and Related Work
> Slideshow’s pict language is by no means the first
> language designed for generating pictures, and its
> picture constructors are similar to those of Henderson’s
> functional pictures [6], MLgraph [1],
> Pictures [5], FPIC [8], pic [9], MetaPost [7], and many
> other systems.
> ...

(The discussion continues in the paper.)

On Wed, Jul 7, 2021 at 4:29 PM Stephen De Gabrielle
 wrote:
>
> Hi
>
> Was the ‘functional geometry’ paper by Peter Henderson in 1982 the 
> inspiration for the pict and 2htdp/image functional picture libraries?
>
> Bw
> Stephen
>
> https://eprints.soton.ac.uk/257577/1/funcgeo2.pdf
>
> --
> 
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/racket-users/CAGHj7-%2B%2B2tq2FJUNb27xw0%3DtHypq%2BgfMW9vWH4fxTtJXMYF%2BkA%40mail.gmail.com.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAMTzy%2BZiodERkbKRckATDJe04AsZ6WLPdNr0MwMiOWwFLhR4FA%40mail.gmail.com.


Re: [racket-users] Re: machine and network outage at Northeastern

2021-07-02 Thread Shu-Hung You
The PLaneT website (https://planet.racket-lang.org/) is currently
unreachable. The error message is ERR_CONNECTION_REFUSED.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAMTzy%2Bb9GkCr_rpFnwUUTrB1PCoXsb%2BCBnEv1cbxNtqK2nKF9A%40mail.gmail.com.


Re: [racket-users] Why would writing to a pipe fail?

2021-06-16 Thread Shu-Hung You
Out of curiosity, I wrapped David's code in a loop and tried to write
509 bytes in each iteration. From the output, it looks like CS doesn't
implement pipes using a fixed-size buffer. I'm also not sure how many
different buffers there are. I think this has something to do with
George's question.

ITERATION 0
avail: 16777216
space available? #t
pipe content length: 0
rx buffer overflow. pipe content length: 15, written 15, expected 509

ITERATION 1
avail: 16777201
space available? #t
pipe content length: 15
rx buffer overflow. pipe content length: 31, written 16, expected 509

ITERATION 2
avail: 16777185
space available? #t
pipe content length: 31
rx buffer overflow. pipe content length: 63, written 32, expected 509

ITERATION 3
avail: 16777153
space available? #t
pipe content length: 63
rx buffer overflow. pipe content length: 127, written 64, expected 509

ITERATION 4
avail: 16777089
space available? #t
pipe content length: 127
rx buffer overflow. pipe content length: 255, written 128, expected 509
done

On Wed, Jun 16, 2021 at 4:34 PM George Neuner  wrote:
>
>
> On 6/16/2021 3:45 PM, Matthew Flatt wrote:
> > At Wed, 16 Jun 2021 14:25:40 -0400, George Neuner wrote:
> > > It looks like the problem
> > > is that "flush" is not defined ...
> >
> > Yes, "returns without blocking after writing as many bytes as it can
> > immediately flush" is vague, and more or less intentionally so. The
> > intent it really "writes as much as is convenient, with the guarantee
> > that anything written is completely flushed". Maybe the documentation
> > should be revised to say something more like that.
> >
> > There's not intended to be a guarantee that as much is written as could
> > possibly make sense by `write-bytes-avail`. Implementation issues may
> > make writing additional bytes inconvenient enough that it doesn't
> > happen, for example, even if more is always written on the next
> > `write-bytes-avail*` call. Also, ports are meant to be used in
> > concurrent settings where the notion "as much as possible" is prone to
> > race conditions.
>
> Dumb question ... why should non-blocking I/O worry about "flush" at
> all.  Why not behave like native I/O where writes are guaranteed only to
> get to the I/O buffer?
>
>
> > The Racket BC and CS pipe implementations find different things
> > convenient, in this sense, and that's why they behave differently in
> > the example. (That is, it's not really about the Racket version, but CS
> > versus BC.)
> >
> > So, the intent is that you use `write-bytes` when you want to wait
> > until all bytes are written (maybe because you know that will be soon
> > enough, for whatever reason). But when using `write-bytes-avail`, be
> > prepared for a fraction of the bytes to be written, for whatever
> > reason.
>
> It is not a problem, per se, but it is an issue that with a long string,
> you may be forced to call  write-bytes-avail  multiple times just to be
> filling up the port buffer.  That seems very inefficient and is at odds
> with how native non-blocking I/O calls behave (completing or filling the
> buffer before returning).
>
> YMMV,
> George
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/racket-users/5257581b-e863-2a2c-e3a3-802b79016281%40comcast.net.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAMTzy%2BbU4i7Rb28HuY%3DTGh0GdHMATdJrM7pjto5jD9h%2Bf_VxOw%40mail.gmail.com.


Re: [racket-users] Defining a function with the same name as a struct with a different constructor name

2021-06-03 Thread Shu-Hung You
In addition to the constructor, `foo` is also used for compile-time
struct information. To avoid this, either supply #:name to designate a
different identifier for compile-time struct type information, or
declare #:omit-define-syntaxes to dismiss it.

Shu-hung

On Thu, Jun 3, 2021 at 4:04 PM Sage Gerard  wrote:
>
> My understanding is that you can shadow `foo`, but you cannot use `foo` in 
> any expression at the same scope where the struct's bindings appear. In this 
> context, some of `foo`'s lexical information is reserved so that `struct-out` 
> works correctly.
>
> On 6/3/21 5:01 PM, flirora wrote:
>
>
> Am I correct in assuming that given a definition like
>
> (struct foo (x) #:constructor-name bar)
>
> I then can't define something named foo in the same module, even though 
> there's no constructor called foo?
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/racket-users/02598ee4-4461-4815-bd4f-a8ac02c1118cn%40googlegroups.com.
>
> --
> ~slg
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/racket-users/76c51dda-b80d-d74a-c691-d92fe11008e8%40sagegerard.com.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAMTzy%2Bav%3Dh_muCMK9pH0FpmUvUU7t5rUFBk09a3zhT7DSAc_1g%40mail.gmail.com.


Re: [racket-users] student produces absolutely bonkers environment lookup code

2021-05-07 Thread Shu-Hung You
Not that I have any idea of what's going on, but interestingly, Typed
Racket's second ->* example has (1)(3)(4). The use of list* may be
possible if one follows the type (List* String Natural x) in the
example.

https://docs.racket-lang.org/ts-reference/type-ref.html?#%28form._%28%28lib._typed-racket%2Fbase-env%2Fbase-types-extra..rkt%29._-~3e%2A%29%29

Shu-Hung

On Fri, May 7, 2021 at 10:53 AM 'John Clements' via Racket Users
 wrote:
>
> Background: I teach a PL course, using Shriram’s PLAI. Many of the 
> assignments require students to maintain an environment mapping symbols to 
> values. Shriram illustrates a nice easy way to do this, as a list of 
> two-element structures. You can also use an immutable hash. Fine. So I’m 
> grading a student submission, and I come across this:
>
> (: extend-environment* (-> Environment (Listof (List Symbol Value)) 
> Environment))
> (define (extend-environment* env kv)
>   (let loop ([kv : (Listof (List Symbol Value)) kv]
>  [env env])
> (cond
>   [(empty? kv) env]
>   [else
>(let* ([kv-pair (first kv)]
>   [new-env (KVEnvironment (first kv-pair) (second kv-pair) env)])
>  (loop (rest kv) new-env))])))
>
>
> ;; Returns a new environment with old-env as parent
> (: extend-environment (->* (Environment Symbol Value) #:rest-star (Symbol 
> Value) Environment))
> (define (extend-environment env key value . kv)
>   (define kv* : (Listof (List Symbol Value))
> (let loop : (Listof (List Symbol Value))
>   ([kv : (Rec x (U Null (List* Symbol Value x))) (list* key value kv)])
>   (if (empty? kv)
>   '()
>   (let* ([take-two (list (first kv) (second kv))]
>  [drop-two (rest (rest kv))])
> (list* take-two (loop drop-two))
>   (extend-environment* env kv*))
>
> This solution uses
>
> 1) a named let,
> 2) the list* function,
> 3) a ->* type with a #:rest-star argument, and
> 4) A custom rec type for alternating symbols and values.
>
> To cap it all off, the student DOESN’T EVEN USE the extra hardware. This is 
> the only use of extend-environment in the code:
>
> (extend-environment e name arg)
>
> So, uh, any idea where this code came from?
>
> :)
>
> John
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/racket-users/ee31119c-aab4-48e4-94dd-39272dd34724%40mtasv.net.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAMTzy%2BZDuZbSW3ga%2BeDdiXhfgJSZpNS2u_nhB%2Bj9u40tYKXJKQ%40mail.gmail.com.


Re: [racket-users] put-image

2021-02-17 Thread Shu-Hung You
One option is using save-image from 2htdp/image to save the images as
PNG files and open them using external programs.
https://docs.racket-lang.org/teachpack/2htdpimage.html#%28def._%28%28lib._2htdp%2Fimage..rkt%29._save-image%29%29

If you can use a different language (say racket), another option is
using show-pict from pict:

;; needs the 'require' form from racket (or racket/base)
(require racket/gui/base (only-in pict show-pict))
(show-pict
 (put-image
  (circle 50 "solid" "green")
  50
  50
  (square 100 "solid" "blue")))

Since many functions in pict have the same names as those provided by
2htdp/image, you need only-in to require only the show-pict function.

On Tue, Feb 16, 2021 at 2:53 PM patric...@gmail.com
 wrote:
>
> I was able to use the Bootstrap teachpack. I am running my program from the 
> command line and racket returns #. Is there a way to view the output 
> outside of Dr. Racket?
>
> On Sunday, February 7, 2021 at 4:51:27 PM UTC-5 Robby Findler wrote:
>>
>> Okay, I've added it. It is pretty straightforward to define it in your own 
>> code in the meantime, Patrick:
>>
>> (define (put-image i1 x y i2)
>>   (place-image i1 x (- (image-height i2) y) i2))
>>
>> Robby
>>
>>
>> On Sun, Feb 7, 2021 at 5:32 AM Stephen De Gabrielle  
>> wrote:
>>>
>>> +1
>>>
>>>
>>> On Sun, 7 Feb 2021 at 03:41, Robby Findler  
>>> wrote:

 Any objection to adding it to 2htdp/image?

 Robby

 On Sat, Feb 6, 2021 at 6:32 PM Sorawee Porncharoenwase 
  wrote:
>
> As explained in documentation of WeScheme, put-image is only available in 
> WeScheme. Racket and its libraries don’t have this function.
>
> It’s easy to implement it yourself, however, by using place-image and 
> image-height. Both are available in 2htdp/image
>
>
> On Sat, Feb 6, 2021 at 3:24 PM patric...@gmail.com  
> wrote:
>>
>>
>> What do I need to do to be able to use the "put-image" method from 
>> WeScheme? I am starting off my program with:
>>
>> #lang htdp/bsl
>>
>> (require 2htdp/image)
>>
>> Is there another package I need to use?
>>
>> --
>> You received this message because you are subscribed to the Google 
>> Groups "Racket Users" group.
>> To unsubscribe from this group and stop receiving emails from it, send 
>> an email to racket-users...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/racket-users/c8788557-0fe6-46a2-be1a-1dbb432ab939n%40googlegroups.com.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/racket-users/CADcuegvDB8a%2BN13xcr6dcgDo4z92sDqDA%2BkU%3DhjnHffGN1h8Vg%40mail.gmail.com.

 --
 You received this message because you are subscribed to the Google Groups 
 "Racket Users" group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to racket-users...@googlegroups.com.
 To view this discussion on the web visit 
 https://groups.google.com/d/msgid/racket-users/CAL3TdOPsOKNE6VF606sgX2TZMwug5siPXEiXuVhjSZTfD4JP5A%40mail.gmail.com.
>>>
>>> --
>>> 
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups 
>>> "Racket Users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send an 
>>> email to racket-users...@googlegroups.com.
>>>
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/racket-users/CAGHj7-KsQQsx0be-m6mG4ORsMgr9zr2qWh2JZc3QH%2B_RZG7YZA%40mail.gmail.com.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/racket-users/e80e29fd-cc01-40c8-8a4d-6ffaeac7cd85n%40googlegroups.com.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAMTzy%2Badc8Cr7qYeFSYzMKgE9Euz3X1SLHMAuupjBgpLercLhA%40mail.gmail.com.


Re: [racket-users] Error while compiling Racket BC

2021-02-05 Thread Shu-Hung You
The snapshot build here may help: https://snapshot.racket-lang.org/

The HEAD version could add new internal primitives from time to time.

Shu-Hung

On Fri, Feb 5, 2021 at 5:52 PM 'Killian Zhuo (KDr2)' via Racket Users
 wrote:
>
> Thank you, does that mean I need a v8.0.0.5 to compile a v8.0.0.5?
>
> I thought v7.9 is new enough...
>
> Greetings.
>
> Killian Zhuo (KDr2, https://kdr2.com)
>
>
>
> On Saturday, February 6, 2021, 07:47:41 AM GMT+8, Sam Tobin-Hochstadt 
>  wrote:
>
>
> This means that you're building with a previous version of Racket that is too 
> old (which might be quite recent but is nonetheless too old to use in place 
> of bootstrapping).
>
> Sam
>
> On Fri, Feb 5, 2021, 6:44 PM 'Killian Zhuo (KDr2)' via Racket Users 
>  wrote:
>
> Here is my configure command:
>
> ./configure --enable-cs --enable-bc --enable-csdefault 
> --enable-racket=$HOME/programs/racket/bin/racket
>
> $HOME/programs/racket/bin/racket is a prebuilt Racket whose version is 7.9.
>
> Then I ran `make cs` and `make install-cs`, all worked well.
>
> Then `make bc` it also worked well, but when I ran `make install-bc`, some 
> errors occured:
>
> make[4]: Entering directory '/data/zhuoql/Work/hall/racket/racket/src/bc'
> if [ "" = "" ]; then \
>   echo "/data/zhuoql/Work/hall/racket/racket/lib"; \
> fi
> /data/zhuoql/Work/hall/racket/racket/lib
> make[4]: Leaving directory '/data/zhuoql/Work/hall/racket/racket/src/bc'
> make[3]: Leaving directory '/data/zhuoql/Work/hall/racket/racket/src'
> make[2]: Leaving directory '/data/zhuoql/Work/hall/racket/racket/src'
> cd bc && make install-setup-3m SELF_ROOT_CONFIG_FLAG="-Z" 
> PLT_SETUP_OPTIONS="" SETUP_MACHINE_FLAGS=""
> make[2]: Entering directory '/data/zhuoql/Work/hall/racket/racket/src/bc'
> /data/zhuoql/programs/racket/bin/racket -X 
> "/data/zhuoql/Work/hall/racket/racket/collects" -G 
> "/data/zhuoql/Work/hall/racket/racket/etc"  -Z ../../../../build/config  
> --no-user-path -N "raco" -l- setup --no-user
> raco setup: bootstrapping from source...
>  read-compiled-linklet: version mismatch  expected: "7.9"  found: "8.0.0.5"  
> in: 
> /data/zhuoql/Work/hall/racket/racket/collects/compiler/private/compiled/cm-minimal_rkt.zo
> /data/zhuoql/Work/hall/racket/racket/collects/racket/fixnum.rkt:12:9: 
> provide: provided identifier is not defined or required
>   at: fx+/wraparound
>   in: (#%provide (expand (provide-trampoline fx->fl fl->fx fxabs fx+ fx- fx* 
> fx+/wraparound fx-/wraparound fx*/wraparound fxquotient fxremainder fxmodulo 
> fxand fxior fxxor fxnot fxrshift fxlshift fxlshift/wraparound fx>= fx> fx= 
> fx< fx<= fxmin fxmax fixnum-fo...
>   location...:
>/data/zhuoql/Work/hall/racket/racket/collects/racket/fixnum.rkt:12:9
>   context...:
>
> /data/zhuoql/Work/hall/racket/racket/collects/compiler/private/cm-minimal.rkt:610:0:
>  compile-zo*
>
> /data/zhuoql/Work/hall/racket/racket/collects/compiler/private/cm-minimal.rkt:409:15
>
> /data/zhuoql/Work/hall/racket/racket/collects/compiler/private/cm-minimal.rkt:374:0:
>  maybe-compile-zo
>
> /data/zhuoql/Work/hall/racket/racket/collects/compiler/private/cm-minimal.rkt:208:0:
>  compile-root
>
> /data/zhuoql/Work/hall/racket/racket/collects/compiler/private/cm-minimal.rkt:144:4:
>  compilation-manager-load-handler
>
> /data/zhuoql/Work/hall/racket/racket/collects/compiler/private/cm-minimal.rkt:610:0:
>  compile-zo*
>
> /data/zhuoql/Work/hall/racket/racket/collects/compiler/private/cm-minimal.rkt:409:15
>
> /data/zhuoql/Work/hall/racket/racket/collects/compiler/private/cm-minimal.rkt:374:0:
>  maybe-compile-zo
>
> /data/zhuoql/Work/hall/racket/racket/collects/compiler/private/cm-minimal.rkt:208:0:
>  compile-root
>
> /data/zhuoql/Work/hall/racket/racket/collects/compiler/private/cm-minimal.rkt:144:4:
>  compilation-manager-load-handler
>
> /data/zhuoql/Work/hall/racket/racket/collects/compiler/private/cm-minimal.rkt:610:0:
>  compile-zo*
>
> /data/zhuoql/Work/hall/racket/racket/collects/compiler/private/cm-minimal.rkt:409:15
>
> /data/zhuoql/Work/hall/racket/racket/collects/compiler/private/cm-minimal.rkt:374:0:
>  maybe-compile-zo
>
> /data/zhuoql/Work/hall/racket/racket/collects/compiler/private/cm-minimal.rkt:208:0:
>  compile-root
>
> /data/zhuoql/Work/hall/racket/racket/collects/compiler/private/cm-minimal.rkt:144:4:
>  compilation-manager-load-handler
>
> /data/zhuoql/Work/hall/racket/racket/collects/compiler/private/cm-minimal.rkt:610:0:
>  compile-zo*
>...
> Makefile:469: recipe for target 'install-setup-3m' failed
> make[2]: *** [install-setup-3m] Error 1
> make[2]: Leaving directory '/data/zhuoql/Work/hall/racket/racket/src/bc'
> Makefile:179: recipe for target 'install-3m' failed
> make[1]: *** [install-3m] Error 2
> make[1]: Leaving directory '/data/zhuoql/Work/hall/racket/racket/src'
> Makefile:114: recipe for target 'install-bc' failed
> make: *** [install-bc] Error 2
>
>
>
> I worked on the head of the master branch, anyone knows 

Re: [racket-users] HtDP Tool Linklet Instantiation Error

2021-01-06 Thread Shu-Hung You
Some update:

Hopefully this is the same issue as the one reported at
https://github.com/racket/racket/issues/3604 and that the commit
https://github.com/racket/drracket/commit/3a07fc0319097661d27ea05ba42634f2b5ae14dd
fixes it.

On Sun, Jun 17, 2018 at 10:15 PM Shu-Hung You
 wrote:
>
> No, this happened even after I did `raco setup`
>
> On Sun, Jun 17, 2018 at 9:47 PM, Robby Findler
>  wrote:
> > Are you editing the files (and not running "raco setup")?
> >
> > Robby
> >
> >
> > On Sun, Jun 17, 2018 at 11:16 AM, Shu-Hung You
> >  wrote:
> >> Does anyone ever get random HtDP plugin linklet instantiation error at
> >> DrRacket startup? I sometimes get these errors, but they would
> >> disappear if I restart DrRacket a few times. The modules that trigger
> >> the errors seem arbitrary too.
> >>
> >> instantiate-linklet: mismatch;
> >>  reference to a variable that is unintialized;
> >>  possibly, bytecode file needs re-compile because dependencies changed
> >>   name: idY365.1
> >>   exporting instance: "/racket/collects/syntax/id-table.rkt"
> >>   importing instance: 
> >> "/racket/collects/racket/match/struct.rkt"
> >>
> >>
> >>
> >> Error invoking tool
> >> #/racket/share/pkgs/htdp-lib/lang>;"htdp-langs.rkt"
> >>
> >> instantiate-linklet: mismatch;
> >>  reference to a variable that is unintialized;
> >>  possibly, bytecode file needs re-compile because dependencies changed
> >>   name: make-fun-syntax
> >>   exporting instance: "/racket/collects/ffi/unsafe.rkt"
> >>   importing instance:
> >> "/racket/share/pkgs/draw-lib/racket/draw/unsafe/cairo.rkt"
> >>
> >>
> >>
> >> Error invoking tool
> >> #/racket/share/pkgs/htdp-lib/lang>;"htdp-langs.rkt"
> >>
> >> instantiate-linklet: mismatch;
> >>  reference to a variable that is unintialized;
> >>  possibly, bytecode file needs re-compile because dependencies changed
> >>   name: idX48.1
> >>   exporting instance: "/racket/collects/racket/dict.rkt"
> >>   importing instance:
> >> "/racket/collects/syntax/parse/lib/function-header.rkt"
> >> instantiate-linklet: mismatch;
> >>  reference to a variable that is unintialized;
> >>  possibly, bytecode file needs re-compile because dependencies changed
> >>   name: parse-function-header1.1
> >>   exporting instance:
> >> "/racket/collects/syntax/parse/lib/function-header.rkt"
> >>   importing instance: 
> >> "/racket/collects/racket/match/match.rkt"
> >>
> >>
> >>
> >> Error invoking tool
> >> #/racket/share/pkgs/htdp-lib/lang>;"htdp-langs.rkt"
> >>
> >> instantiate-linklet: mismatch;
> >>  reference to a variable that is unintialized;
> >>  possibly, bytecode file needs re-compile because dependencies changed
> >>   name: idY365.1
> >>   exporting instance: "/racket/collects/syntax/id-table.rkt"
> >>   importing instance: 
> >> "/racket/collects/racket/match/struct.rkt"
> >>
> >>
> >> The error contexts are like:
> >>
> >>   context...:
> >>for-loop
> >>run-module-instance!125
> >>for-loop
> >>loop
> >>[repeats 1 more time]
> >>expand-capturing-lifts
> >>loop
> >>.../racket/unit.rkt:1001:20
> >>
> >> /extra-pkgs/drracket/drracket/drracket/private/tools-drs.rkt:56:0:
> >> invoke-drs-tool
> >>.../more-scheme.rkt:261:28
> >>
> >> /extra-pkgs/drracket/drracket/drracket/private/tools.rkt:72:0:
> >> load/invoke-all-tools
> >>.../racket/unit.rkt:1001:20
> >>"/extra-pkgs/drracket/drracket/drracket/tool-lib.rkt":
> >> [running body]
> >>for-loop
> >>run-module-instance!125
> >>
> >> "/extra-pkgs/drracket/drracket/drracket/private/drracket-normal.rkt":
> >> [running body]
> >>...
> >>
> >>   context...:
> >>for-loop
> >>run-module-instance!125
> >>for-loop
> >>loop
> >>[repeats 1 more time]
> >>expand-capturing-lifts
> >>loop
> >>.../racket/unit.rkt:1001:20
> >>
> >> /extra-pkgs/drracket/drracket/drracket/private/tools-

Re: [racket-users] Is there a function to find and update all compiled directories?

2020-11-01 Thread Shu-Hung You
Using the command-line instruction `raco setup` will update all
obsolete bytecodes. If you are looking for a programmable interface,
`compiler/cm` is a good starting point.

On Sun, Nov 1, 2020 at 5:43 PM infodeveloperdon
 wrote:
>
> I've never had problems with the .zo files being auto-created during 
> development, only when update the Racket version because of course then a new 
> compiler is involved. If I am remembering correctly, any time I've had issues 
> with the compiled files, I've resolved them by deleting the compiled 
> directory identified by the error message. Which only makes me wonder if 
> there is some function I am unaware of that will update compiled directories 
> without needing to specify the path to each one, or find and delete them all 
> (Racket recreates them).
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/racket-users/1169e7cf-80b2-4093-b3be-f9253993188cn%40googlegroups.com.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAMTzy%2BaUhRQWt_LkeKgJxsOL33-sd6Hbv7Qgu5oCVvXti0cHFA%40mail.gmail.com.


Re: [racket-users] Clearer code in DrRacket?

2020-10-09 Thread Shu-Hung You
Here is an example that provides different colors for some particular
forms such as define, require, lambda etc. However, these forms
('keywords') are recognized literally by the lexer instead of
semantically as in Check Syntax. Therefore it will classify
non-keywords as keywords from time to time.
https://github.com/shhyou/drracket-scheme-dark-green

More color schemes can be found here:
https://pkgd.racket-lang.org/pkgn/search?tags=colorscheme

On Fri, Oct 9, 2020 at 9:12 AM Adam El Mazouari
 wrote:
>
> An example is this:
>
> (define (square-all lst) (if (null? lst)
>
> '()
> (cons (square (car lst))
>
> (square-all (cdr lst)
>
>
> As you can see, you've got:
>
> methods included by default (define, cons)
> booleans (null?)
> user-introduced vars (lst)
>
> shown in the same color. It's really not clear. I'd like for them to be in 
> different colors.
>
> --Adam.
>
> On Fri, Oct 9, 2020 at 3:35 PM Sam Tobin-Hochstadt  
> wrote:
>>
>> Can you give an example of which things you'd like to be different? We
>> usually use "variable" and "identifier" for very similar meanings when
>> discussing Racket, for example.
>>
>> Sam
>>
>> On Fri, Oct 9, 2020 at 8:16 AM Adam El Mazouari
>>  wrote:
>> >
>> > Hello everyone.
>> >
>> > I've started using DrRacket a couple of weeks ago and I can't get used to 
>> > the color theme. Variables, identifiers, methods, all of them are in blue. 
>> > It's really unintuitive. Does anybody know a good plugin that 
>> > differentiates these in a clear way for the human eye?
>> >
>> > Or, if you know something better than DrRacket in that regard, feel free 
>> > to write down.
>> >
>> > Thanks in advance!
>> >
>> > Adam
>> >
>> > --
>> > You received this message because you are subscribed to the Google Groups 
>> > "Racket Users" group.
>> > To unsubscribe from this group and stop receiving emails from it, send an 
>> > email to racket-users+unsubscr...@googlegroups.com.
>> > To view this discussion on the web visit 
>> > https://groups.google.com/d/msgid/racket-users/0ddf205e-c461-40d3-857b-4b5f75e60284n%40googlegroups.com.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/racket-users/CAEGV_UybZ_m15Np%2BrJ51JWPhVkMhahESp9pRUet1%3DOTG5YOddQ%40mail.gmail.com.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAMTzy%2Ba6DJR8OeqdOors%3D5HbbV7VxT%3DTmrt6U46OK8hzF2oc9w%40mail.gmail.com.


Re: [racket-users] Re: with-continuation-marks in errortrace

2020-07-27 Thread Shu-Hung You
Thinking about your example again, is the idea here to preserve the
first (so perhaps outermost) continuation mark information, instead of
the innermost continuation mark? I don't yet fully understand how this
approach interacts with the evaluation of tail position expressions,
but keeping both seems pretty useful.

Regarding the (* (loop (sub1 n)) n) information, as I understand
errortrace does wrap subexpressions. Here is the instrumentation
result of (* (loop (sub1 n)) n):

  (with-continuation-mark ek:errortrace-key '((* (loop (sub1 n)) n) SRCLOC)
(#%app
*
(with-continuation-mark ek:errortrace-key '((loop (sub1 n)) SRCLOC)
  (#%app
loop
(with-continuation-mark ek:errortrace-key '((sub1 n) SRCLOC)
  (#%app sub1 n
n))

A guess is that the continuation mark value '((loop (sub1 n)) SRCLOC)
is being overwritten by its subsequent evaluation to (* (loop (sub1
n)) n). This provides error-centric backtrace information.

What I can think about the effect of keeping only the outermost
continuation mark is that the control-flow information w.r.t. tail
expressions will be lost. In the following (unreal) example, there
will be no chance to identify which (/ y 0) caused the error.

On Mon, Jul 27, 2020 at 1:13 PM Shu-Hung You  wrote:
>
> By changing (fact 5) to (* 2 (fact 5)), the stack information becomes
>
> /: division by zero
>   errortrace...:
>/Volumes/ramdisk/fact.rkt:6:17: (/ 1 0)
>/Volumes/ramdisk/fact.rkt:7:12: (* (loop (sub1 n)) n)
>/Volumes/ramdisk/fact.rkt:7:12: (* (loop (sub1 n)) n)
>/Volumes/ramdisk/fact.rkt:7:12: (* (loop (sub1 n)) n)
>/Volumes/ramdisk/fact.rkt:7:12: (* (loop (sub1 n)) n)
>/Volumes/ramdisk/fact.rkt:7:12: (* (loop (sub1 n)) n)
>/Volumes/ramdisk/fact.rkt:9:0: (* 2 (fact 5))
>
> Here, the difference is that (fact 5) is no longer at tail position. I
> believe errortrace is aiming at preserving proper tail implementation
> behavior.
>
> On Mon, Jul 27, 2020 at 11:39 AM Sorawee Porncharoenwase
>  wrote:
> >
> > (By "integrating" with the new strategy, I meant having two keys: one for 
> > the new strategy and one for the old strategy. I can see that the first 
> > entry of the old strategy is useful, and it's missing in the new strategy).
> >
> > On Sun, Jul 26, 2020 at 8:21 PM Sorawee Porncharoenwase 
> >  wrote:
> >>
> >> Hi everyone,
> >>
> >> I have a question about the implementation of errortrace.
> >>
> >> Consider the classic factorial program, except that the base case is buggy:
> >>
> >> (define (fact m)
> >>   (let loop ([n m])
> >> (cond
> >>   [(zero? n) (/ 1 0)]
> >>   [else (* (loop (sub1 n)) n)])))
> >>
> >> (fact 5)
> >>
> >> Running this program with racket -l errortrace -t fact.rkt gives the 
> >> following output:
> >>
> >> /: division by zero
> >>   errortrace...:
> >>/Users/sorawee/playground/fact.rkt:9:17: (/ 1 0)
> >>/Users/sorawee/playground/fact.rkt:10:12: (* (loop (sub1 n)) n)
> >>/Users/sorawee/playground/fact.rkt:10:12: (* (loop (sub1 n)) n)
> >>/Users/sorawee/playground/fact.rkt:10:12: (* (loop (sub1 n)) n)
> >>/Users/sorawee/playground/fact.rkt:10:12: (* (loop (sub1 n)) n)
> >>/Users/sorawee/playground/fact.rkt:10:12: (* (loop (sub1 n)) n)
> >>
> >> I find this result subpar: it doesn’t indicate which call at the top-level 
> >> leads to the error. You can imagine another implementation of fact that 
> >> errors iff m = 5. Being able to see that (fact 5) at the top-level causes 
> >> the error, as opposed to (fact 3), would be very helpful.
> >>
> >> Not only that, (* (loop (sub1 n)) n) also looks weird. There’s nothing 
> >> wrong with multiplication, so I don’t find this information useful.
> >>
> >> The tail-recursive factorial is similarly not helpful:
> >>
> >> (define (fact m)
> >>   (let loop ([n m] [acc 1])
> >> (cond
> >>   [(zero? n) (/ 1 0)]
> >>   [else (loop (sub1 n) (* n acc))])))
> >>
> >> (fact 5)
> >>
> >> produces:
> >>
> >> /: division by zero
> >>   errortrace...:
> >>/Users/sorawee/playground/fact.rkt:9:17: (/ 1 0)
> >>
> >> 
> >>
> >> I have been toying with another way to instrument the code. It roughly 
> >> expands to:
> >>
> >> (define-syntax-rule (wrap f)
> >>   (call-with-immediate-continuation-mark
> >>'errortrace-k
> >>(λ (k)
&g

Re: [racket-users] Re: with-continuation-marks in errortrace

2020-07-26 Thread Shu-Hung You
By changing (fact 5) to (* 2 (fact 5)), the stack information becomes

/: division by zero
  errortrace...:
   /Volumes/ramdisk/fact.rkt:6:17: (/ 1 0)
   /Volumes/ramdisk/fact.rkt:7:12: (* (loop (sub1 n)) n)
   /Volumes/ramdisk/fact.rkt:7:12: (* (loop (sub1 n)) n)
   /Volumes/ramdisk/fact.rkt:7:12: (* (loop (sub1 n)) n)
   /Volumes/ramdisk/fact.rkt:7:12: (* (loop (sub1 n)) n)
   /Volumes/ramdisk/fact.rkt:7:12: (* (loop (sub1 n)) n)
   /Volumes/ramdisk/fact.rkt:9:0: (* 2 (fact 5))

Here, the difference is that (fact 5) is no longer at tail position. I
believe errortrace is aiming at preserving proper tail implementation
behavior.

On Mon, Jul 27, 2020 at 11:39 AM Sorawee Porncharoenwase
 wrote:
>
> (By "integrating" with the new strategy, I meant having two keys: one for the 
> new strategy and one for the old strategy. I can see that the first entry of 
> the old strategy is useful, and it's missing in the new strategy).
>
> On Sun, Jul 26, 2020 at 8:21 PM Sorawee Porncharoenwase 
>  wrote:
>>
>> Hi everyone,
>>
>> I have a question about the implementation of errortrace.
>>
>> Consider the classic factorial program, except that the base case is buggy:
>>
>> (define (fact m)
>>   (let loop ([n m])
>> (cond
>>   [(zero? n) (/ 1 0)]
>>   [else (* (loop (sub1 n)) n)])))
>>
>> (fact 5)
>>
>> Running this program with racket -l errortrace -t fact.rkt gives the 
>> following output:
>>
>> /: division by zero
>>   errortrace...:
>>/Users/sorawee/playground/fact.rkt:9:17: (/ 1 0)
>>/Users/sorawee/playground/fact.rkt:10:12: (* (loop (sub1 n)) n)
>>/Users/sorawee/playground/fact.rkt:10:12: (* (loop (sub1 n)) n)
>>/Users/sorawee/playground/fact.rkt:10:12: (* (loop (sub1 n)) n)
>>/Users/sorawee/playground/fact.rkt:10:12: (* (loop (sub1 n)) n)
>>/Users/sorawee/playground/fact.rkt:10:12: (* (loop (sub1 n)) n)
>>
>> I find this result subpar: it doesn’t indicate which call at the top-level 
>> leads to the error. You can imagine another implementation of fact that 
>> errors iff m = 5. Being able to see that (fact 5) at the top-level causes 
>> the error, as opposed to (fact 3), would be very helpful.
>>
>> Not only that, (* (loop (sub1 n)) n) also looks weird. There’s nothing wrong 
>> with multiplication, so I don’t find this information useful.
>>
>> The tail-recursive factorial is similarly not helpful:
>>
>> (define (fact m)
>>   (let loop ([n m] [acc 1])
>> (cond
>>   [(zero? n) (/ 1 0)]
>>   [else (loop (sub1 n) (* n acc))])))
>>
>> (fact 5)
>>
>> produces:
>>
>> /: division by zero
>>   errortrace...:
>>/Users/sorawee/playground/fact.rkt:9:17: (/ 1 0)
>>
>> 
>>
>> I have been toying with another way to instrument the code. It roughly 
>> expands to:
>>
>> (define-syntax-rule (wrap f)
>>   (call-with-immediate-continuation-mark
>>'errortrace-k
>>(λ (k)
>>  (let ([ff (thunk f)])
>>(if k
>>(ff)
>>(with-continuation-mark 'errortrace-k 'f
>>  (ff)))
>>
>> (define (handler ex)
>>   (continuation-mark-set->list (exn-continuation-marks ex) 'errortrace-k))
>>
>> (define (fact m)
>>   (wrap (let loop ([n m])
>>   (wrap (cond
>>   [(wrap (zero? n)) (wrap (/ 1 0))]
>>   [else (wrap (* (wrap n) (wrap (loop (wrap (sub1 
>> n))])
>>
>> (with-handlers ([exn:fail? handler])
>>   (wrap (fact 5)))
>>
>> which produces:
>>
>> '((loop (wrap (sub1 n)))
>>   (loop (wrap (sub1 n)))
>>   (loop (wrap (sub1 n)))
>>   (loop (wrap (sub1 n)))
>>   (loop (wrap (sub1 n)))
>>   (fact 5))
>>
>> This result is more aligned with the traditional stacktrace, and gives 
>> useful information that I can use to trace to the error location.
>>
>> It is also safe-for-space:
>>
>> (define (fact m)
>>   (wrap (let loop ([n m] [acc 1])
>>   (wrap (cond
>>   [(wrap (zero? n)) (wrap (/ 1 0))]
>>   [else (wrap (loop (wrap (sub1 n)) (wrap (* n acc])
>>
>> (with-handlers ([exn:fail? handler])
>>   (wrap (fact 5)))
>>
>> produces:
>>
>> '((fact 5))
>>
>> Now, the question: why is the current errortrace implemented in that way? Am 
>> I missing any downside of this new strategy? Would switching and/or 
>> integrating with the new strategy be better?
>>
>> Thanks,
>> Sorawee (Oak)
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/racket-users/CADcuegto9%2BDtFTwAVmiReOcCwpARzBSbFhF0knyexb7UhoHQiA%40mail.gmail.com.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on 

Re: [racket-users] make-set!-transformer

2020-06-24 Thread Shu-Hung You
Here it is.
https://github.com/racket/racket/blob/master/pkgs/racket-doc/scribblings/reference/stx-trans.scrbl#L31

I agree that it will be good to have a pointer or an example involving
set!-values in the documentation of make-set!-transformer. The status
quo is kind of indirect. The documentation of set!-values explains
that set!-values is expanded into let-values plus set!, and the reader
has to connect the two in order to infer the applicability of
set!-transformers to set!-values forms.

https://docs.racket-lang.org/reference/set_.html#%28form._%28%28lib._racket%2Fprivate%2Fmore-scheme..rkt%29._set%21-values%29%29

On Wed, Jun 24, 2020 at 7:09 PM Jos Koot  wrote:
>
> The docs on make-set!-transformer do not mention that it also applies to 
> set!-values.
>
> That is does apply to both is a good case, I think. I have tried to find the 
> documentation  on the GitHub of racket but could not find it. Please give me 
> a hint where to look, so I can do a pull request for submitting a suggestion 
> of improvement. That is, if such an improvement is wanted, of course. I often 
> have trouble to find docs  code on Racket’s GitHub.
>
> If my suggestion is welcome I am willing to do the job by myself! Just as to 
> be a tiny contributor by myself.
>
> Jos
>
>
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/racket-users/5ef3eb1e.1c69fb81.c3c6e.5819%40mx.google.com.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAMTzy%2BYeASRxnGiv6zQG%3DA6%2B3Og%2BiL7AUc%3DU%2Bp074KH5n0ZnpQ%40mail.gmail.com.


Re: [racket-users] syntax woe with typed Racket 'let'

2020-06-01 Thread Shu-Hung You
FWIW, because `.` is just cons, the program
(define (F [X : T1] . [Y : T2]) 'e)
is being read as:
(define (F [X : T1] Y : T2) 'e)
I guess that's the reason for having an extra '*' in the syntax.

On Mon, Jun 1, 2020 at 10:16 PM Sam Tobin-Hochstadt
 wrote:
>
> The syntax looks like this:
>
> (define (f [x : Number] . [y : String *]) : Number (+ x (length y)))
>
> See the documentation for `define` in Typed Racket here:
> https://docs.racket-lang.org/ts-reference/special-forms.html?q=define#%28form._%28%28lib._typed-racket%2Fbase-env%2Fprims..rkt%29._define%29%29
> in particular the `rst` production.
>
> Sam
>
> On Mon, Jun 1, 2020 at 3:09 PM Hendrik Boom  wrote:
> >
> > On Mon, Jun 01, 2020 at 10:58:09AM -0400, Sam Tobin-Hochstadt wrote:
> > > Do you perhaps have some other binding shadowing the binding of `:`
> > > from Typed Racket? That produces the error message you get when I try
> > > it.
> >
> > Not intentionally.  I'll have to look carefully for possible candidates.
> > Or ask DrRacket to jump to a binding occurrence.
> >
> > Did that:  It wouldn't find a bining instance while that colon was
> > there, but complained about the syntax error I was sompaining about.
> > But when I removed the type specification from the let-clause and
> > introuced a colon elsewhere in the function as an extra parameter in
> > another expression, it would find the binding.  It turned out that the
> > binding occurrence was the colon in the tail-parameter [args : T-Size].
> >
> > So I have to ask, what *is* the proper way to indicate that the
> > function can be called with many more parameters, which are to be
> > made available as a list?
> >
> > Thank you for the hint.
> >
> > -- hendrik
> >
> > >
> > > Sam
> > >
> > > On Sat, May 30, 2020 at 1:32 PM Hendrik Boom  
> > > wrote:
> > > >
> > > > I'm sorry to keep pestering this list, but I'm out of my depth with the
> > > > detailed syntax (and semantics) of typed Racket.  But I'm doggedly
> > > > ploughing on.
> > > >
> > > > I'm having trouble with the 'let' line in the 'pointer-to' function 
> > > > listed later:
> > > >
> > > > (let ([vt : Ffi-type (cast ((inst hash-ref Ffi-type Ffi-type) 
> > > > type-to-vector type #f) Ffi-type)])
> > > >
> > > > Yes, there's an unbalanced parenthesis because this sin't the end of 
> > > > the let-expression.
> > > >
> > > > The error message is
> > > >
> > > >  let: expected type-annotated identifier
> > > >   parsing context:
> > > >while parsing annotated-binding
> > > >while parsing optionally type-annotated binding in: (vt : Ffi-type 
> > > > (cast ((inst hash-ref Ffi-type Ffi-type) type-to-vector type #f) 
> > > > Ffi-type))
> > > >
> > > > I can't see the error.  'vt : Ffi-type' looks like a type-annotated
> > > > identifier to me.  And it seems to have the right number of parentheses
> > > > in front of it, followed by an expression whose vlue is to be bound to
> > > > 'vt'.
> > > >
> > > > Here's the function it's part of:
> > > >
> > > >
> > > > (define (pointer-to [type : T-Type] . [args : T-Size]) : T-Type ; TODO: 
> > > > rename args to size-args
> > > >   (if (and (equal? args '(1)) (not (eq? type '_void)))
> > > > (mode-dependent-type
> > > >   `(_ptr i ,type) `(_ptr o ,type))
> > > > (case type
> > > >   ((_void) '_pointer/intptr)
> > > >   ((_byte _uint8) (mode-dependent-type
> > > > '_string*/utf-8
> > > > (if (null? args)
> > > >   '_bytes
> > > >   `(_bytes o ,@ args
> > > >   (else
> > > > (let ([vt : Ffi-type (cast ((inst hash-ref Ffi-type Ffi-type) 
> > > > type-to-vector type #f) Ffi-type)])
> > > >   (if vt
> > > > (mode-dependent-type
> > > >   `(,vt i)
> > > >   (if (null? args)
> > > > vt
> > > > `(,vt o ,@ args)))
> > > > (mode-dependent-type
> > > >   `(_vector i ,type)
> > > >   (if (null? args)
> > > > '_pointer
> > > > `(_vector o ,type ,@ args)
> > > >
> > > > --
> > > > You received this message because you are subscribed to the Google 
> > > > Groups "Racket Users" group.
> > > > To unsubscribe from this group and stop receiving emails from it, send 
> > > > an email to racket-users+unsubscr...@googlegroups.com.
> > > > To view this discussion on the web visit 
> > > > https://groups.google.com/d/msgid/racket-users/20200530173230.bsrp5skkc35ot34h%40topoi.pooq.com.
> > >
> > > --
> > > You received this message because you are subscribed to the Google Groups 
> > > "Racket Users" group.
> > > To unsubscribe from this group and stop receiving emails from it, send an 
> > > email to racket-users+unsubscr...@googlegroups.com.
> > > To view this discussion on the web visit 
> > > https://groups.google.com/d/msgid/racket-users/CAK%3DHD%2BYkANXdevMc%3DiSTFaWnpzU-6ofNWF2qJtWyR-f6ES2gLg%40mail.gmail.com.
> >

Re: [racket-users] Annoying run-warnings in DrR 7.5: How to disable?

2020-01-24 Thread Shu-Hung You
On Fri, Jan 24, 2020 at 10:37 PM Jordan Johnson  wrote:
>
> On 24 Jan 2020, at 14:00, Robby Findler  wrote:
> > In the preferences dialog, in the General tab, the last checkbox is
> > the one you want.
>
> The one for saving files upon switching tabs?
>

That new options is added in the upcoming v7.6 release.

> > But let me confirm: the reason it is painful to turn on the preference
> > is that you have to choose a file?
>
> Well, I hadn’t ever turned on the preference before, so I didn’t know whether 
> it would necessitate choosing a file. But in answer to your question, no. See 
> below.
>
> > Would it work well for you if it
> > only wanted to save files that already had filenames?
>
> AFAICT now that I’ve turned on that preference, this is the behavior it has. 
> It doesn’t prompt me to save an untitled file. And this is the behavior I 
> would want, if DrR is saving upon tab-switching.
>
> It feels weird to me to have DrR save files when I switch tabs; I’m somewhat 
> trained to use the “modified” state as a marker that I’m in the middle of 
> something, and “is everything saved?” is a part of my “am I done?” mental 
> checklist when I’m working on multiple unrelated things in different tabs. 
> I’ll have to impose a different discipline on myself (which may be for the 
> best).
>
> For now, I’ll try living with the preference enabled for a while. I don’t 
> foresee doing any complicated work this spring, so it’s no big deal right now.
>
> Thanks for the reply.
>
> Cheers,
> Jordan
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/racket-users/2702DF36-1CB7-40F3-AF5D-3D0AABC8D395%40fellowhuman.com.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAMTzy%2BYUdVmvwY7atim68BgRR5cCzDv_nHO%2BvwxxQ%2BiQSqpAFw%40mail.gmail.com.


Re: [racket-users] Re: Installing Drracket on linux penguin on Chromebook

2020-01-17 Thread Shu-Hung You
What's the result of `file
/home/user/racket-tmp-install/bin/racket` and the result of
`uname -a`?

(In other words, what hardware are you using? Is it 32-bit or 64-bit,
it is x86 or ARM? Which version of Racket did you download?)

On Fri, Jan 17, 2020 at 12:21 PM William Dobias
 wrote:
>
> Thank you:
> So I tried this (with basic troubleshooting, e.g., a couple times, with 
> troubleshooting: restarted linux, chromebook; etc.) and it's not working:
>
> ```
> Checking the integrity of the binary archive... ok.
> Unpacking into "/home/user/racket-tmp-install" (Ctrl+C to abort)...
> Done.
> ./racketinst.sh: 513: ./racketinst.sh: 
> /home/user/racket-tmp-install/bin/racket: Exec format error
> Error: installation failed
>   (Removing installation files in /home/user/racket-tmp-install)
> ```
>
> I am not sure what that means? The processor is aarch64 -architecture if that 
> is relevant. Is that what exec format means?
>
>
>
> On Wednesday, 15 January 2020 14:55:37 UTC-5, William Dobias wrote:
>>
>> I am taking a course that uses drracket. I am having trouble installing it 
>> on my Chromebook (through the penguin linux) does anyone have any 
>> suggestions?
>>
> --
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/racket-users/1edb5947-a6ec-4ac5-bfb2-7d9974c1ea8e%40googlegroups.com.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAMTzy%2BZs_9zP4mYwZ16yjccmH_Cvdnf2mZ5Wx0eFDwKHxF64Cw%40mail.gmail.com.


Re: [racket-users] Installing Drracket on linux penguin on Chromebook

2020-01-16 Thread Shu-Hung You
Here's what I did:

1. Download the installer for x86_64 linux.
2. Move (or copy) the downloaded .sh file _into_ penguin through Files App.
3. Allow the installer to run by using `chmod +x FILE` (or `chmod 755 FILE`)
   * Chromrebook does not allow eXecutable permission
 for files outside penguin.
4. Run the installer (`./FILE`). I believe installing Racket in its
own directory (either in the current directory or under ~/) is the
simplest option.

On Wed, Jan 15, 2020 at 1:56 PM William Dobias
 wrote:
>
> I am taking a course that uses drracket. I am having trouble installing it on 
> my Chromebook (through the penguin linux) does anyone have any suggestions?
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/racket-users/90d60948-32b1-4ed8-adbc-3c2f913ca3af%40googlegroups.com.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAMTzy%2BbDt%2BSXAaP4Zr3coFzTuhTA1icoL0%3D1gWTWddSF-oc4Rg%40mail.gmail.com.


[racket-users] Running DrRacket on Chromebook

2020-01-07 Thread Shu-Hung You
Hi Racketeers,

How can I run Racket/DrRacket on a Chromebook?

I found two ways to run Linux on top of Chromebook, and thus two ways
to run DrRacket:

1. Built-in Linux (Beta) App
2. Crouton, but requires entering developer mode

When Linux App is not available, is Crouton the only option left?

Best,
Shu-Hung

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAMTzy%2BY4Qo5_qSiz22tjSGzH8kiHiW8LSOcV2WWcM1CG0r8MAQ%40mail.gmail.com.


Re: [racket-users] file-position in Win32 not working beyond 1 GB

2019-12-20 Thread Shu-Hung You
On Fri, Dec 20, 2019 at 2:05 PM Shu-Hung You
 wrote:
>
> Could it be that the Racket layer importing rktio C code directly uses
> get-ffi-obj and does not convert scheme_bignum_type to _int64?
>

Never mind this -- I got the FFI part wrong.

> On Fri, Dec 20, 2019 at 2:01 PM Matthew Flatt  wrote:
> >
> > The Racket-imposed limit should be 64 bits (more than enough) on all
> > platforms. I can try to replicate the problem later today, but more
> > information on the error message would be helpful.
> >
> > At Fri, 20 Dec 2019 17:39:37 +0300, Dmitry Pavlov wrote:
> > > Hello,
> > >
> > > On a fresh 32-bit Racket 7.5 install on 32-bit Windows 7,
> > > (file-position port number) does not work when number
> > > is more that 1 GB.
> > >
> > > I can not now say exactly what the error message was,
> > > because I am away from that system, but IIUC it
> > > was something about the position being "too large".
> > >
> > > The size of the file, though, is definitely large enough
> > > to have that position, and (file-position port number)
> > > on it worked fine until the number grew beyond
> > > the said limit.
> > >
> > > On 64-bit Linux, everything is fine.
> > >
> > > Can I work this problem around somehow?
> > >
> > > Best regards
> > >
> > > Dmitry
> > >
> > > --
> > > You received this message because you are subscribed to the Google Groups
> > > "Racket Users" group.
> > > To unsubscribe from this group and stop receiving emails from it, send an
> > > email to racket-users+unsubscr...@googlegroups.com.
> > > To view this discussion on the web visit
> > > https://groups.google.com/d/msgid/racket-users/22f36172-daf8-7e6f-5f55-9e1c562b
> > > 8b61%40iaaras.ru.
> >
> > --
> > You received this message because you are subscribed to the Google Groups 
> > "Racket Users" group.
> > To unsubscribe from this group and stop receiving emails from it, send an 
> > email to racket-users+unsubscr...@googlegroups.com.
> > To view this discussion on the web visit 
> > https://groups.google.com/d/msgid/racket-users/5dfd2879.1c69fb81.2bbe.ad80SMTPIN_ADDED_MISSING%40gmr-mx.google.com.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAMTzy%2BZq5tyFGM23yZ3zVcgSCwt_QUPN6XtSL0SppkZj8hKaFw%40mail.gmail.com.


Re: [racket-users] file-position in Win32 not working beyond 1 GB

2019-12-20 Thread Shu-Hung You
Could it be that the Racket layer importing rktio C code directly uses
get-ffi-obj and does not convert scheme_bignum_type to _int64?

@Dmitry: I guess Racket uses 1 bit for type tagging, leaving only
30+sign (or 62+sign) bits for the actual value.

On Fri, Dec 20, 2019 at 2:01 PM Matthew Flatt  wrote:
>
> The Racket-imposed limit should be 64 bits (more than enough) on all
> platforms. I can try to replicate the problem later today, but more
> information on the error message would be helpful.
>
> At Fri, 20 Dec 2019 17:39:37 +0300, Dmitry Pavlov wrote:
> > Hello,
> >
> > On a fresh 32-bit Racket 7.5 install on 32-bit Windows 7,
> > (file-position port number) does not work when number
> > is more that 1 GB.
> >
> > I can not now say exactly what the error message was,
> > because I am away from that system, but IIUC it
> > was something about the position being "too large".
> >
> > The size of the file, though, is definitely large enough
> > to have that position, and (file-position port number)
> > on it worked fine until the number grew beyond
> > the said limit.
> >
> > On 64-bit Linux, everything is fine.
> >
> > Can I work this problem around somehow?
> >
> > Best regards
> >
> > Dmitry
> >
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Racket Users" group.
> > To unsubscribe from this group and stop receiving emails from it, send an
> > email to racket-users+unsubscr...@googlegroups.com.
> > To view this discussion on the web visit
> > https://groups.google.com/d/msgid/racket-users/22f36172-daf8-7e6f-5f55-9e1c562b
> > 8b61%40iaaras.ru.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/racket-users/5dfd2879.1c69fb81.2bbe.ad80SMTPIN_ADDED_MISSING%40gmr-mx.google.com.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAMTzy%2BbxJw-tGzmnpWGkvpab_1zW9QM%2BAgJBftJncAHSFrEz4g%40mail.gmail.com.


Re: [racket-users] reading code

2019-11-12 Thread Shu-Hung You
On Mon, Nov 11, 2019 at 10:30 AM Hendrik Boom  wrote:
>
> On Fri, Oct 25, 2019 at 11:31:41AM +0200, Niklas Larsson wrote:
> > Hi!
> >
> > If you right click on an identifier in drracket you get “jump to binding 
> > occurrence” and “jump to definition” (if it’s defined in another file). 
> > Don’t those do what you want?
>
> Close.
>
> Using "jump to binding occurrence" gets me to the require
> line that provides me the symbol.  I can then ask it to open
> that file, but if the other file just imports a number of other
> modules and provides all-from-out it still leaves me a bit lost.
>
> I turn out not to have "jump to definition" but
> "open defining file", which creates a new tab.  Then I still
> have to search for the name I was looking for.  But at least
>  can find it.
>
> -- hendrik
>

After opening the defining file and after a little green dot shows up
at the bottom-right corner in DrRacket, the "Open Defining File" menu
item will become "Jump to Definition (in Other File)". That will let
you directly jump to the definition site.

(Sadly contract-out identifiers will still defeat Check Syntax.)

Shu-Hung

> >
> > Regards,
> > Niklas
> >
> > > 24 okt. 2019 kl. 17:46 skrev Hendrik Boom :
> > >
> > > What tools are there to help understand large Racket programs?
> > >
> > > I'm trying to grok the innards of Pict3D, which is, I believe, typed
> > > Racket.
> > >
> > > But I have difficulty finding bindings of symbols across many complex
> > > require's and provide's through many directories of source code.
> > >
> > > I'm looking for tools that work on a Linux system.  I know that in
> > > principle I could install something like Microsoft's big fat
> > > development environment (which may have a plugin for Racket)
> > > but it would surpise me if there wasn't something relevant within the
> > > Racket ecosystem.
> > >
> > > If DrRacket already does this, I haven't found it.  It does lovely
> > > graphics do show bindings, but I don't see how to follow those lines
> > > even to parts of the same file that happen to be out of the window
> > > area, let alone to other files.
> > >
> > > Does DrRacket also show the types of symbols or expressions in typed
> > > Racket?
> > >
> > > -- hendrik
> > >
> > > --
> > > You received this message because you are subscribed to the Google Groups 
> > > "Racket Users" group.
> > > To unsubscribe from this group and stop receiving emails from it, send an 
> > > email to racket-users+unsubscr...@googlegroups.com.
> > > To view this discussion on the web visit 
> > > https://groups.google.com/d/msgid/racket-users/20191024154608.f3n3parggb2t5ckj%40topoi.pooq.com.
> >
> > --
> > You received this message because you are subscribed to the Google Groups 
> > "Racket Users" group.
> > To unsubscribe from this group and stop receiving emails from it, send an 
> > email to racket-users+unsubscr...@googlegroups.com.
> > To view this discussion on the web visit 
> > https://groups.google.com/d/msgid/racket-users/3B855EDE-EE87-4D96-A6F3-35C5BCFF2D0A%40gmail.com.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/racket-users/2019162958.ybiunmwlvj2hqj23%40topoi.pooq.com.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAMTzy%2BbtV6simooivDAdJCiX-wmR-4bDveEeTuoLnZwuiFLbuA%40mail.gmail.com.


Re: [racket-users] scribble cannot find module that racket finds

2019-11-03 Thread Shu-Hung You
On Sun, Nov 3, 2019 at 2:26 PM Hendrik Boom  wrote:
>
> scribble does not find module "inclusion.rkt" even though racket does.
> There must be a work-around, mustn't there?
>
> I can (require "inclusion.rkt") jusr fine from racket
>
> t3.rkt:
>
> #lang racket
> (require "inclusion.rkt")
> foo
>
> inclusion.rkt:
>
> #lang racket
> (define foo 'foo)
> (provide foo)
>
> running it:
>
>
> hendrik@midwinter:~/dv/scribble$ racket t3.rkt
> 'foo
> hendrik@midwinter:~/dv/scribble$
>
>
>
> But when I try from scribble it goes wrong:
>
> t3.scrbl:
>
> #lang scribble
> @(require "inclusion.rkt")
> foo
>
> same inclusion.rkt file
>
> Run it:
>
>
> hendrik@midwinter:~/dv/scribble$ scribble t3.scrbl
> standard-module-name-resolver: collection not found
>   for module path: scribble/lang/reader
>   collection: "scribble/lang"

The error message here is a little opaque, but the actual cause is
that `#lang scribble' does not exist. The available languages include:

;; https://docs.racket-lang.org/scribble/generic-prose.html
#lang scribble/base
#lang scribble/manual (like Racket doc)
#lang scribble/book
#lang scribble/report
(and more)

>   in collection directories:
>/home/hendrik/.racket/snapshot/collects
>/home/hendrik/racket-7.4.0.1/collects
>... [166 additional linked and package directories]
>   context...:
>show-collection-err
>standard-module-name-resolver
>module-path-index-resolve
>do-dynamic-require5
>read-syntax3
>default-load-handler
>standard-module-name-resolver
>module-path-index-resolve
>module-declared?
>loop
>...cket/cmdline.rkt:191:51
>"/home/hendrik/racket-7.4.0.1/share/pkgs/scribble-lib/scribble/run.rkt": 
> [running body]
>temp37_0
>for-loop
>run-module-instance!125
>perform-require!78
> hendrik@midwinter:~/dv/scribble$
>
> (and no, I don't expect it to find the foo provided by the module.  This foo 
> is plain
> scribble text).  But it fails before it gets that far.
>
>
> Is there a way to require packages into scribble that *does* work?
>
>
> -- hendrik
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/racket-users/20191103202649.2msxe24kkg4sleow%40topoi.pooq.com.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAMTzy%2BaRs1Nf3tEq1EMzqJSRaMGG-fSenUi8GuizLvhJw7raog%40mail.gmail.com.


Re: [racket-users] Does match against list traverse the whole list?

2019-10-29 Thread Shu-Hung You
>From the expansion result, match does check whether the inspected
value is a list using list?. But at least for the current version of
Racket (and the C VM), list? is handled specially and ``effectively
takes constant time due to internal caching.'' (quoted from:
https://docs.racket-lang.org/reference/pairs.html?q#(def._((quote._~23~25kernel)._list~3f))
)

On Tue, Oct 29, 2019 at 12:41 PM Christopher Lemmer Webber
 wrote:
>
> Imagine the following code:
>
> (let lp ([items '(1 2 3 4 5)])
>   (match items
> [(list head rest ...)
>  (cons (* head 2)
>(lp rest))]))
>
> My gut feeling is "oh, this is just O(n) because it's pulling the top
> off the list quite efficient."
>
> But then I realized that:
>
> (match '(1 2 3 4 . 5)
>   [(list head rest ...)
>(* head 2)])
>
> throws an exception because it's a dotted list.
>
> But the documentation says that the `list?` predicate is O(n).  I'm
> suddenly fearing, have I been writing O(n^2) code this whole time?  Does
> match against list actually check the whole list every time?
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/racket-users/87lft3xxdo.fsf%40dustycloud.org.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAMTzy%2BZ6z6EETExv-5QaDdKy-nG%3DVF%2BC3N4w0VoMNwLL%3D0gikA%40mail.gmail.com.


Re: [racket-users] Racket COM error opening Word document: expected argument of type <(opt (box any))>

2019-10-08 Thread Shu-Hung You
I don't know COM but here's an attempt to guess what happened based on
the documentation.

On Tue, Oct 8, 2019 at 11:51 AM Scott Gudeman  wrote:
>
> I am working on converting a powershell script to Racket that takes a Word 
> XML document and saves it as PDF.
>
> In powershell, when I call Word's `Documents.Open` method I can just pass it 
> the naked string as the file path without anything special done to it. In 
> Racket, however, when I run the following code I get an error telling me the 
> type is bad
>
> ```
>   (define xml-document (string-append (path->string (path->complete-path 
> (build-path (find-system-path 'orig-dir)  "temp"))) "\\" tag ".xml"))
>   (define pdf-document (string-append (path->string (simplify-path 
> (path->complete-path (build-path 'up "formatted")) #t)) "\\" tag ".pdf"))
>   (define word-instance (com-create-instance "Word.Application"))
>   (define word-document (com-invoke (com-get-property word-instance 
> "Documents") "Open" xml-document))
>   (com-invoke book "ExportAsFixedFormat"
>   pdf-document
>   17 com-omit com-omit com-omit com-omit com-omit com-omit com-omit 
> com-omit
>   1)
>   (com-invoke book "Close")
>   (com-invoke word-instance "Quit")
>   (com-release word-instance)
>
> ```
> This gives the following error on the line the **define word-document**
>
> > Open: expected argument of type <(opt (box any))>; given:
> > "...\\pdf_gen\\temp\\filename.xml"
>
>
> I am very confused by this as the documentation suggests that I should be 
> able to plug in the path as a string, the error suggests otherwise?
>

Based on the message, the method expects a value whose type
description is '(opt (box any)). From 5.17.1.9, this means that this
is an optional, call-by-reference (probably means a pointer in C
sense) argument and that on Racket's side it expects the callee to
modify the argument. I'm wondering if this would work:

(define word-document (com-invoke (com-get-property word-instance
"Documents") "Open" (box xml-document)))

5.17.1.9 COM Types
https://docs.racket-lang.org/foreign/com-auto.html#%28part._com-types%29


> I've tried both the regular and CS versions of Racket 7.4
>
> Relevant Racket and Word documentation:
>
> [Racket COM 
> Documentation](https://docs.racket-lang.org/foreign/com-auto.html?q=com)
>
> [MS Word COM Open 
> Method](https://docs.microsoft.com/en-us/dotnet/api/microsoft.office.interop.word.documents.open?view=word-pia#parameters)
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/racket-users/423334b3-607e-4041-b046-06528c0ea5d7%40googlegroups.com.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAMTzy%2BY%2BOux1m4eWt%2BktN%2BYa-yVD4wkERhWH9Z2Kk%3D6vUwm7sg%40mail.gmail.com.


Re: [racket-users] handin-server: writing a first checker

2019-08-23 Thread Shu-Hung You
I forgot to CC my reply to the list. The case here is that the user
account data in `users.rktd` only contain one field but the default
`extra-fields` configuration requires 3 extra fields. The error
message probably comes from some (map cons  ...)
expression that resides in the server code.




On Thu, Aug 22, 2019 at 9:00 AM Matthew Flatt  wrote:
>
> I'm not able to provoke this error with the pieces that you provided.
>
> Just to be sure, it's not an error in the submission that you sent to
> the handin server, right? Normally the error in that case would be
> "Error in your code", so I think that's not it. But does the error
> depend on the program that you send as a submission?
>
> At Wed, 21 Aug 2019 21:32:58 +, "'Wayne Harris' via Racket Users" wrote:
> > I haven't been able to write a first checker.  I'm always getting
> >
> >   map: all lists must have same size
> >
> > in the server's log.
> >
> > The submission always shows this in the log file:
> >
> > [16|2019-08-21T21:12:35] connect from 191.35.15.190
> > [16|2019-08-21T21:12:39] running 12KB (123MB 133MB)
> > [16|2019-08-21T21:12:39] login: (wharr...@protonmail.com)
> > [16|2019-08-21T21:12:39] assignment for (wharr...@protonmail.com): 
> > assignment-1
> > [16|2019-08-21T21:12:40] timeout-control: reset
> > [16|2019-08-21T21:12:40] checking assignment-1 for (wharr...@protonmail.com)
> > [16|2019-08-21T21:12:42] running 37KB (123MB 133MB)
> > [16|2019-08-21T21:12:46] running 37KB (123MB 133MB)
> > [16|2019-08-21T21:12:49] running 39KB (123MB 133MB)
> > [16|2019-08-21T21:12:52] ERROR: map: all lists must have same size
> > [16|2019-08-21T21:12:52]   first list length: 3
> > [16|2019-08-21T21:12:52]   other list length: 1
> > [16|2019-08-21T21:12:52]   procedure: #
> >
> > It also pops up the message error message to the student in DrRacket.
> >
> > Any ideas what's causing this?
> >
> > Taking the typical checker from the documentation, I started with:
> >
> > (module checker handin-server/checker
> >   (check: :language  '(special intermediate)
> > (!procedure Fahrenheit->Celsius 1)
> > (!test (Fahrenheit->Celsius  32)   0)
> > (!test (Fahrenheit->Celsius 212) 100)
> > (!test (Fahrenheit->Celsius  -4) -20)))
> >
> > My student code in DrRacket is set to intermediate language and the
> > code is:
> >
> > (define (Fahrenheit->Celsius x)
> >   (* 5/9 (- x 32)))
> >
> > (check-expect (Fahrenheit->Celsius 32) 0)
> >
> > Here's my server configuration:
> >
> > $ cat config.rktd
> >  ((active-dirs ("assignment-1"))
> >   (allow-web-upload #t)
> >   (allow-new-users #t)
> >   (master-password "4c96f8324e3ba54a99e78249b95daa30"))
> > $
> >
> > $ cat users.rktd
> > (
> >  (wharr...@protonmail.com ("4c96f8324e3ba54a99e78249b95daa30" "Wayne 
> > Harris"))
> > )
> > $
> >
> > $ cat assignment-1/checker.rkt
> > (module checker handin-server/checker
> >   (check: :language  '(special intermediate)
> > (!procedure Fahrenheit->Celsius 1)
> > (!test (Fahrenheit->Celsius  32)   0)
> > (!test (Fahrenheit->Celsius 212) 100)
> > (!test (Fahrenheit->Celsius  -4) -20)))
> > $
> >
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Racket Users" group.
> > To unsubscribe from this group and stop receiving emails from it, send an
> > email to racket-users+unsubscr...@googlegroups.com.
> > To view this discussion on the web visit
> > https://groups.google.com/d/msgid/racket-users/Le2v4fuorTS76ru-EzIcXTxB9t0I3wyV
> > 56qTFtRFY8cErV3l4mIJVUsi-s9qSlv7Q_2PVix-prxqDh5noOcmrlm3yyeB7gdBx02fwaUICW8%3D%
> > 40protonmail.com.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/racket-users/5d5ea010.1c69fb81.71fbf.0dbdSMTPIN_ADDED_MISSING%40gmr-mx.google.com.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAMTzy%2Bb1%3DCyF-wGbf_%2BqZsU1imRAHpnO0Bo2PKwpYbC%3D_LdaGw%40mail.gmail.com.


Re: [racket-users] Re: Using errortrace with repl-driven-development?

2019-07-24 Thread Shu-Hung You
errortrace with ,en should work as normal, as long as you ensure that
there are no pre-compiled bytecode files (compiled/*.zo):

$ ls
myfile.rkt
$ racket -l errortrace -i
Welcome to Racket v7.2.
> ,en "myfile.rkt"
"myfile.rkt"> (f 123)
; g: 123 [,bt for context]
"myfile.rkt"> ,bt
; g: 123
;   errortrace...:
;/tmp/ram2/debug/myfile.rkt:6:2: (error (quote g) "~a" n)
;/tmp/ram2/debug/myfile.rkt:3:2: (+ (g x) (g (+ 2 x)))
..

If myfile.rkt is precompiled then errortrace wouldn't have the chance
to instrument it with backtrace information:

$ raco make myfile.rkt && ls *
myfile.rkt

compiled:
myfile_rkt.dep  myfile_rkt.zo
$ racket -l errortrace -i
Welcome to Racket v7.2.
> ,en "myfile.rkt"
"myfile.rkt"> (f 456)
; g: 456 [,bt for context]
"myfile.rkt"> ,bt
; g: 456
;   errortrace...:
;readline-input:2:0: (f 456)
..

On Wed, Jul 24, 2019 at 5:36 AM Anthony Quizon  wrote:
>
>
> Thanks! This one was what is needed.
>
> racket -l errortrace -l racket -i
>
> Actually, I tried this on my own before but I kept on getting "(no 
> backtrace)" when I would run my file.
> Turns out, you can only get the stacktrace if you run the code via the repl 
> input rather than running code within the file (ie. using ",en")
>
> On Wednesday, July 24, 2019 at 12:43:27 PM UTC+10, Alex Harsanyi wrote:
>>
>> If you are using DrRacket, you can go to the "Language/Choose Language..." 
>> menu, click on "Show Details", than make sure the "Preserve Stack Trace" 
>> checkbox is ticked.
>>
>> If you are using racket-mode in Emacs, you can evaluate the current buffer 
>> using "C-u F5" which will do the same thing.
>>
>> If you use racket from the command line, I think you can run it as:
>>
>> racket -l errortrace -l racket -i
>>
>> Hope this helps,
>> Alex.
>>
>> On Wednesday, July 24, 2019 at 9:45:47 AM UTC+8, Anthony Quizon wrote:
>>>
>>> I've been trying to find a way to get better error messages in the racket 
>>> repl via the command line.
>>> Specifically, better stack traces. At the moment, if you load a file in the 
>>> repl via ',enter' it doesn't give you any information about the line number 
>>> for errors.
>>>
>>> I've looked around in the users group but could only find:
>>> racket -l errortrace -t .rkt
>>>
>>> This is pretty much what I'm looking for except that it only lets me use 
>>> this once and non-interactively.
>>>
>>> Is there an option in the (x)repl that lets me use errortrace interactively 
>>> for each input?
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/racket-users/650ddb71-44ca-4758-bd08-a2b606a2f5b0%40googlegroups.com.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAMTzy%2BZ5R68c85JjfX08MxnO%3D%2ByJ%2BFRgBFKrO9eHu8OKpVpVNg%40mail.gmail.com.


Re: [racket-users] file-position does not extend file as expected

2019-06-24 Thread Shu-Hung You
On Mon, Jun 24, 2019 at 4:09 PM David Storrs  wrote:
>
> I actually did try writing something at the extended position, although I 
> removed it before posting the above.  Even with a write, it still does not do 
> as expected.  In fact, the results are even stranger:
>
> #lang racket
>
> (define (say . args) (displayln (apply ~a args)))
> (define the-path "./test-file")
> (when (file-exists? the-path)  (delete-file the-path))
> (say "before open, file exists?: " (file-exists? the-path))
>
> (let ([the-port (open-output-file the-path #:mode 'binary #:exists 'append)])
>   (say "after open, file exists?: " (file-exists? the-path))
>   (say "before repos, file size, position: " (file-size the-path) ", "
>(file-position the-port))
>   (file-position the-port 1000); should extend the file and fill the 
> intervening space with 0
>   (say "before flush, file size, position: " (file-size the-path) ", "
>(file-position the-port))
>   (flush-output the-port) ; ensure that the filling 0s have been written, 
> just to be sure
>   (say "before write, file size, position: " (file-size the-path) ", "
>(file-position the-port))
>
>   (write "foo" the-port)
>   (say "before 2nd flush, file size, position: "
>(file-size the-path) ", " (file-position the-port))
>   (flush-output the-port)
>   (say "finally, file size, position: " (file-size the-path) ", " 
> (file-position the-port))
>   )
> Ouptut:
>
> before open, file exists?: #f
> after open, file exists?: #t
> before repos, file size, position: 0, 0
> before flush, file size, position: 0, 1000
> before write, file size, position: 0, 1000
> before 2nd flush, file size, position: 0, 1005
> finally, file size, position: 5, 5
>
> Personally, i find this even weirder.  I wrote 3 characters, so why is the 
> file size 5?  (Which it is, on disk.)
>

FWIW, (write "foo") writes "\"foo\"" to the file. Maybe you want
write-string or write-bytes?



> On Mon, Jun 24, 2019 at 4:57 PM Jon Zeppieri  wrote:
>>
>> On Mon, Jun 24, 2019 at 4:51 PM Jon Zeppieri  wrote:
>> >
>> > `lseek` docs say:
>> >
>> > > The lseek() function shall allow the file offset to be set beyond the 
>> > > end of the existing data in the file. If data is later written at this 
>> > > point, subsequent reads of data in the gap shall return bytes with the 
>> > > value 0 until data is actually written into the gap.
>> >
>>
>> And the Windows call `SetFilePosition` is similar:
>>
>> > It is not an error to set a file pointer to a position beyond the end of 
>> > the file. The size of the file does not increase until you call the 
>> > SetEndOfFile, WriteFile, or WriteFileEx function. A write operation 
>> > increases the size of the file to the file pointer position plus the size 
>> > of the buffer written, which results in the intervening bytes 
>> > uninitialized.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/racket-users/CAE8gKodw3c2wqUBdAPKRkX3hqin4fhZ8kjeFKh3LouFhY4-8XQ%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAMTzy%2BbV-SExfSR6LSXX7r_Zpg7gD37LROf__o8C9HxpykaFNQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Re: catch and bind an unbound id in a macro

2019-04-20 Thread Shu-Hung You
identifier-binding returns #f for top-level bindings. I believe
make-base-eval is evaluating expressions at top-level.

On Sat, Apr 20, 2019 at 4:56 PM Ryan Kramer  wrote:
>
> Below is a short example showing that identifier-binding doesn't seem to work 
> quite right with Scribble's make-base-eval. It works fine with make-evaluator 
> from racket/sandbox.
>
> I'm not sure why this is, but using syntax-local-value instead works 
> everywhere. (Implementation here: 
> https://github.com/default-kramer/plisqin/commit/2723d7c11be5b6938e681ea869e8b9f4957849b0#diff-1a91d998f2be05413392d588a89323d3R31)
>
> #lang racket
> (require scribble/eval
>  racket/sandbox)
>
> (define (setup eval)
>   (eval
>'(define-syntax (define-if-not stx)
>   (syntax-case stx ()
> [(_ id val)
>  (identifier-binding #'id)
>  #'(void)]
> [(_ id val)
>  #'(define id val)]
>
> (define scribble-eval (make-base-eval))
> (scribble-eval '(require racket))
> (setup scribble-eval)
>
> (define racket-eval (make-evaluator 'racket))
> (setup racket-eval)
>
> (scribble-eval '(define-if-not foo 1))
> (scribble-eval '(define-if-not foo 2))
> (scribble-eval 'foo) ; want 1, get 2
>
> (racket-eval '(define-if-not bar 3))
> (racket-eval '(define-if-not bar 4))
> (racket-eval 'bar) ; want 3, get 3
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Re: Intriguing performance difference between Windows and Linux on `(factorial 100000)`

2019-03-24 Thread Shu-Hung You
Interesting. This is the timing on Mac. Comparing to Alex's result,
the numbers roughly match "< 7s" v.s. "> 13s" while fact-1 is close.

$ racket
Welcome to Racket v7.2.0.3.
> (enter! "factorial.rkt")
"factorial.rkt"> (equal? (fact 10) (fact-1 10))
#t
"factorial.rkt"> (time (void (fact-1 10)))
cpu time: 313 real time: 314 gc time: 2
"factorial.rkt"> (time (void (fact 10)))
cpu time: 6185 real time: 6265 gc time: 974

The GC time of fact differs a lot.

On Sun, Mar 24, 2019 at 9:26 PM Alex Harsanyi  wrote:
>
> You can check if the big number multiplication is the problem, by using a 
> factorial version which does not need so many big number multiplications:
>
> #lang racket/base
> (require racket/math)
> (define (fact n)
>   (if (zero? n) 1 (* n (fact (- n 1)
>
> (define (fact-1 n)
>   (define nslots (exact-truncate (sqrt n)))
>   (if (<= nslots 1)
>   (fact n) ;; use simple implementation for small numbers
>   (let ((slot (make-vector nslots 1)))
> (for ([x (in-range 1 (add1 n))])
>   (define index (modulo x nslots))
>   (vector-set! slot index (* (vector-ref slot index) x)))
> (for/fold ([result 1])
>   ([n (in-vector slot)])
>   (* result n)
>
> On my Windows machine, the difference between the two is huge: 16.7 seconds 
> for `fact` (your original implementation)  and only 0.5 seconds for `fact-1`
>
> > (equal? (fact 10) (fact-1 10))
> #t
> > (time (void (fact-1 10)))
> cpu time: 469 real time: 468 gc time: 111
> > (time (void (fact 10)))
> cpu time: 16797 real time: 16782 gc time: 7082
> >
>
>
>
> On Monday, March 25, 2019 at 1:20:33 AM UTC+8, Phil Nguyen wrote:
>>
>> With Racket 7.2, the following program takes >13 seconds to run on Windows, 
>> and <7 seconds on Linux either on Virtualbox on the same machine, or native 
>> Linux on another machine with slightly lower-powered processor:
>>
>> #lang racket/base
>> (define (fact n)
>>   (if (zero? n) 1 (* n (fact (- n 1)
>> (time (void (fact 10)))
>>
>> ; Windows native, i7-7660U
>> ;   cpu time: 13610 real time: 13633 gc time: 4459
>> ; Linux on Virtualbox, i7-7660U
>> ;   cpu time: 6691 real time: 6706 gc time: 1298
>> ; Linux native, i7-8500Y:
>> ;   cpu time: 6894 real time: 6882 gc time: 1129
>>
>>
>>
>> While the difference is unlikely to matter in practice, given `fact 10` 
>> is a very large number, I'm curious what accounts for this difference? Is it 
>> some big-integer library that Racket relies on?
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Cannot use case+else inside match+else

2019-02-27 Thread Shu-Hung You
And because it is nothing else but a usual binding, it's possible to
prefix-in or rename-in as in

(require (prefix-in r: racket/base))
(case 5 [r:else 'ok])

On Wed, Feb 27, 2019 at 7:32 AM Laurent  wrote:
>
> Good point. I wasn't sure that would work---it does.
>
> On Wed, Feb 27, 2019 at 1:28 PM Jens Axel Søgaard  
> wrote:
>>
>> I suppose you could (re)require it again.
>>
>> ons. 27. feb. 2019 kl. 14.19 skrev Laurent :
>>>
>>> Wait, that means that in an interactive session, if you ever happen to 
>>> redefine `else', you can't use `case' anymore?
>>>
>>> On Tue, Feb 26, 2019 at 5:03 AM Ben Greenman  
>>> wrote:

 Here's a suggestion for the docs:

 https://github.com/racket/racket/pull/2505

 --
 You received this message because you are subscribed to the Google Groups 
 "Racket Users" group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to racket-users+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/d/optout.
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups 
>>> "Racket Users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send an 
>>> email to racket-users+unsubscr...@googlegroups.com.
>>> For more options, visit https://groups.google.com/d/optout.
>>
>> --
>> --
>> Jens Axel Søgaard
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Cannot use case+else inside match+else

2019-02-25 Thread Shu-Hung You
Ah!

Thank you for pointing this out. I've always thought that `else' is
treated as a keyword in `match' just as what `cond' does. That
explains everything.

On Mon, Feb 25, 2019 at 6:35 PM Sam Tobin-Hochstadt
 wrote:
>
> This is because 'case' expects a particular binding for 'else', but you 
> shadowed it with 'match', which does not treat 'else' differently than any 
> other identifier.
>
> Sam
>
> On Mon, Feb 25, 2019, 7:33 PM Shu-Hung You 
>  wrote:
>>
>> When using a case expression with an else clause in inside a match
>> expression, the expander complains about case having a bad syntax.
>> However, the use of case expressions outside of match are fine. Is
>> there anyway to get around this?
>>
>> Currently, I just replace it with another match.
>>
>> #lang racket/base
>>
>> (require racket/match)
>>
>> (match 6
>>   [else
>>(case 5
>>  [else 7])])
>>
>> #|
>> unsaved editor:8:6: case: bad syntax (not a datum sequence) at: else
>> in: (case 5 (else 7))
>>   #(78 4)
>> |#
>>
>> --
>> You received this message because you are subscribed to the Google Groups 
>> "Racket Users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to racket-users+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] Cannot use case+else inside match+else

2019-02-25 Thread Shu-Hung You
When using a case expression with an else clause in inside a match
expression, the expander complains about case having a bad syntax.
However, the use of case expressions outside of match are fine. Is
there anyway to get around this?

Currently, I just replace it with another match.

#lang racket/base

(require racket/match)

(match 6
  [else
   (case 5
 [else 7])])

#|
unsaved editor:8:6: case: bad syntax (not a datum sequence) at: else
in: (case 5 (else 7))
  #(78 4)
|#

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] struct-info

2019-02-12 Thread Shu-Hung You
On Tue, Feb 12, 2019 at 3:55 PM David Storrs  wrote:
>
> On Tue, Feb 12, 2019 at 4:46 PM  wrote:
> >>
> >> Thank you for the explanation.  Can I ask why the heck it works this
> >> way?  This seems to be explicitly designed for maximal surprise and
> >> minimal usefulness.
> >
> >
> > It works that way so that, by default, modules can't inspect, modify, or 
> > otherwise muck around with structs defined by other modules. Opaque structs 
> > (that is, structs that aren't transparent and aren't prefab) aren't really 
> > meant to be used like "plain old data objects" with fields and accessors, 
> > they're more like building blocks for abstract data types. A module that 
> > defines an opaque struct type is expected to be responsible for exporting 
> > to other modules all the functions that are necessary for using that type. 
> > Anything not explicitly exported by the module is not allowed, even through 
> > reflective operations like struct-info. The exception to this rule is when 
> > some entity above the modules is controlling them all, such as a debugger, 
> > an IDE, or a server running client-supplied code. In these cases, the 
> > controlling code has the option to make a child inspector and run all the 
> > modules under that child inspector, giving the controlling code access to 
> > all struct types through the parent inspector. This kind of setup can be 
> > nested arbitrarily deep.
>
> I see.  That makes sense.  I think it would be worth expanding the
> documentation on that; I'm happy to provide a suggestion later
> tonight, but I will need to do it through email instead of via pull
> request.  I have long since given up on being able to find anything in
> the Racket github in order to provide patches.  It's simply too
> unintuitive and time-intensive to find the relevant section in
> multiple repositories where the documentation is in randomly-named
> fragments scattered across multiple directories instead of being
> individual files with guessable names.
>
>
> >
> > This is nice for defining abstract types, but it can be pretty inconvenient 
> > for defining plain old aggregated data types that just have a bundle of 
> > fields. When defining those types as structs, consider using the 
> > #:transparent option. This means "use no inspector at all" (roughly) and 
> > lets `struct-info` Just Work (TM) without any inspector wrangling. The 
> > downside is that other modules may be able to break your type's invariants 
> > and possibly circumvent your contracts.
>
> That's what I expected, but it doesn't seem to work:
>
> > (struct person (name age) #:transparent)
> > (struct-info person)
> #f
> #t
>
> What am I missing?
>

It takes an instance of person.

(struct-info (person "Me" 3.14))

FWIW if you already have the struct type descriptor (which is what
struct-info returns), you can directly call struct-type-info.

(struct-type-info
 (let-values ([(desc skip?) (struct-info (person "Me" 3.14))])
   desc))

;; struct:person is introduced by the (struct person ...) form
(struct-type-info struct:person)

> --
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Fully expanded programs grammar: print-values

2019-02-06 Thread Shu-Hung You
On Wed, Feb 6, 2019 at 9:42 AM 'Paulo Matos' via Racket Users <
racket-users@googlegroups.com> wrote:
>
>
>
> On 06/02/2019 16:00, Shu-Hung You wrote:
> > print-values is a normal identifier introduced by the racket/base's
> > macro module-begin. It is a (private) function defined in
> > racket/private/modbeg.
> >
> That's sort of surprising. I actually expected fully expanded programs
> to be evaluable by the user. This obviously can't happen if it expands
> to private functions.
>

Actually, the fully expanded programs _can_ be evaluated by the users. It
is possible to first expand an input program then pass the result to eval.
The identifier has the right binding information, referencing to the
private function in racket/private/modbeg, and that module will be
instantiated because racket/base depends on it.

This sort of expanding to some identifier referring to not-provided
definitions is very common from the use of macros.

#lang racket

(define ns (make-base-namespace))

(define code
  `(,(namespace-module-identifier ns) M racket/base
 (define x 10)
 (+ x 3)))

(pretty-write code)
(define expanded-code (expand code))
(pretty-write (syntax->datum expanded-code))

(parameterize ([current-namespace ns])
  (eval expanded-code)
  (eval '(require 'M)))

To examine the lexical information of an identifier, you can print
expanded-code in DrRacket and click on print-values to see its syntax
information:

[image: binding.png]

> Is there a specific reason for this or just happened and nobody every
cared?
>

I would say this is what the code looks like when you look under the hood.
Macros and modules work with each other like magic; identifiers come with
lexical information. Conceptually, instantiating a module M containing a
variable x would introduce a mapping M.x |-> value in the namespace. If, at
expansion time, some macro in M introduces x to a client module, the x in
the client module is compiled to be a runtime reference to M.x.

This part in the document contains an informal description:
https://docs.racket-lang.org/reference/eval-model.html#(part._module-eval-model)

Matthew wrote a paper about how modules and macros work together:

Matthew Flatt. Composable and Compilable Macros: You Want it When?
https://www.cs.utah.edu/plt/publications/macromod.pdf

The paper contains a model showing how things like 'print-values' work. In
page 9, the grammar of c-exp contains mod.id.p to handle reference to
variables in other modules.

> --
> Paulo Matos
>
> --
> You received this message because you are subscribed to the Google Groups
"Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Fully expanded programs grammar: print-values

2019-02-06 Thread Shu-Hung You
print-values is a normal identifier introduced by the racket/base's macro
module-begin. It is a (private) function defined in racket/private/modbeg.

On Feb 6, 2019 5:02 AM, "'Paulo Matos' via Racket Users" <
racket-users@googlegroups.com> wrote:

> Hi,
>
> The docs[1] give a grammar for fully expanded programs.
> I found it amazingly concise so I decided to give it a try and expanded
> the following:
>
> ```
> #lang racket
>
> 42
> ```
>
> This expands to (nicely formatted):
>
> # (module forty-two racket
>   (#%module-begin
> (module configure-runtime
>   (quote #%kernel)
>   (#%module-begin
> (#%require racket/runtime-config)
> (#%app configure (quote #f
>   (#%app call-with-values (lambda () (quote 42)) print-values)))
> >
>
> That looks good to me. However, in the documented grammar there's no
> reference to print-values. I assume print-values is an `id` in the
> grammar, but I cannot find a reference to `print-values` in the docs
> either. Is this an omission?
>
> [1]
> https://docs.racket-lang.org/reference/syntax-model.html?#(
> part._fully-expanded)
> --
> Paulo Matos
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Re: Redex: making a #lang with native lambda, app, etc.

2019-01-03 Thread Shu-Hung You
Deferring everything to runtime could avoid macros as much as
possible. You can implement input parsing as a function and use the
macro only to glue things together.

#lang racket/base

(require (for-syntax racket/base)
 syntax/parse/define
 redex/reduction-semantics)

(provide (rename-out
  [my-module-begin #%module-begin]))

(define-simple-macro (my-module-begin form ...)
  (#%module-begin (handle-expression 'form) ...))

And the function handle-expression can parse the quoted expression
into the syntax of your model, invoke Redex and print the result:

(define (handle-expression expr)
  (define t (parse-input expr))
  (define results (apply-reduction-relation* R t))
  (write (car results)))

(define (parse-input expr)
  )

(where parse-input is a normal function that turns λ into TermLambda
and inserts TermApp when appropriate.)

On Wed, Jan 2, 2019 at 7:47 PM Joey Eremondi  wrote:
>
> Thanks for the response!
>
> That's not quite what I want. That will quote lambdas and applications into 
> my redex models, but I also want it to reduce them by my reduction relation.
>
> The link I posted discussed how to do that, but only when you write programs 
> in the syntax of the model.
>
> Sorry for not being clear about the top-interaction. There's nothing specific 
> about top-interaction, I'm having the same problem with module-begin.
> I'm trying to get them both to evaluate the terms using my redex model.
>
> The local-expand function in the article you give looks promising, but I'm 
> still figuring out how exactly to use it, particularly with the list of 
> expressions for module-begin.
>
>
> On Monday, December 31, 2018 at 8:47:49 PM UTC-8, Sorawee Porncharoenwase 
> wrote:
>>
>> I'm a novice too, but here's my attempt to help.
>>
>>>
>>> I'd like to use (define-syntax) to make lambda, #%app, etc. all expand into 
>>> terms in my model.
>>
>>
>> This works for me.  Is this what you want?
>>
>> #lang racket/base
>>
>> (require redex)
>>
>> (define-language L
>>   (term ::=
>> (TermLambda var term)
>> var
>> (TermApp term term)))
>>
>> (define-syntax-rule (lambda (x) b)
>>   (term (TermLambda x b)))
>>
>> (default-language L)
>>
>> (lambda (y) y)
>> ;; => '(TermLambda y y)
>>
>> (term (substitute ,(lambda (y) y) y z))
>> ;; => '(TermLambda z z)
>>
>>
>>>
>>> But the problem I'm running into is that #%top-interaction applies (term) 
>>> to its argument, which means that  'lambda' and other macros get quoted and 
>>> not expanded.
>>
>>
>> I don't totally understand how #%top-interaction is relevant here. It only 
>> comes up when you use the REPL, and even then I think it shouldn't do 
>> something like that. What are you trying to do in the REPL? And can't you 
>> redefine #%top-interaction so that it doesn't do what you don't want it to 
>> do?
>>
>>>
>>> Is there a way to make sure that the macros are expanded *before* they are 
>>> passed to term, so that (term) receives valid syntax trees for my model, 
>>> instead of quoted lambdas and apps?
>>
>>
>> See 
>> https://lexi-lambda.github.io/blog/2018/10/06/macroexpand-anywhere-with-local-apply-transformer/.
>>  You can also just use the gist here: 
>> https://gist.github.com/lexi-lambda/65d69043023b519694f50dfca2dc7d33
>>
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Re: Why enter/run a submodule in the REPL?

2018-12-13 Thread Shu-Hung You
Hi Stephan,

The "submodules to run" drop-down menu lets you choose which
submodules will be executed when you click the "Run" button. For
example, if you have a main submodule and a test submodule, DrRacket
will run those 2 submodules by default. You can avoid running tests in
the test submodule by unselecting it from the "submodules to run"
menu. Similarly, perhaps your main submodule parses the command line
arguments and performs some I/O which you would like to avoid when
doing interactive development and restarts the REPL. That's what I
mostly use that menu for.

AFAIK, there's no support for running a submodule in DrRacket REPL.

Shu-Hung
On Thu, Dec 13, 2018 at 4:28 AM Stephen De Gabrielle
 wrote:
>
> Hi,
>
> I suppose a better question is what do any racketeers use ‘submodules to run’ 
> in DrRacket? And if so- what for?
>
> Stephen
>
> On Wed, 12 Dec 2018 at 00:21, Stephen De Gabrielle  
> wrote:
>>
>> Hi,
>>
>> #lang racket
>> (displayln "This is the main module")
>> (module+ drracket
>>   (define foo 'FOO)
>>   (displayln "This is the drracket submodule"))
>>
>> Execute and DrRacket displays "This is the main module" in the interactions 
>> window
>> type
>> (require (only-in racket/enter dynamic-enter!)
>>   (only-in syntax/location quote-module-path))
>> (dynamic-enter! (quote-module-path drracket))
>>
>> and bindings defined in the submodule are then available; e.g.
>> > foo
>> 'FOO
>>
>> Why and how do I use this for interactive development, scripting and 
>> debugging?
>>
>> There is also a DrRacket function (Submodules to Run), but I can't find any 
>> documentation for it.
>>
>>
>> Stephen
>>
>>
> --
> 
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] (pict-snip%) Write: cannot marshal value that is embedded in compiled code value

2018-12-10 Thread Shu-Hung You
Is this some expected behavior?

1. Open DrRacket and run:

#lang racket/base
(require pict)
(circle 50)

2. Copy the output. Open a new tab in DrRacket and paste the pict-snip%.

3. This error message showed up at the bottom: ``write: cannot marshal
value that is embedded in compiled code value: (object:pict-snip%
...)''

Despite the error message, the program saves and runs just fine. I
have Racket version 7.1.0.9.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] (pict-snip%) Write: cannot marshal value that is embedded in compiled code value

2018-12-10 Thread Shu-Hung You
Is this some expected behavior?

1. Open DrRacket and run:

#lang racket/base
(require pict)
(circle 50)

2. Copy the output. Open a new tab in DrRacket and paste the pict-snip%.

3. An error message showed up at the bottom, similar to this
https://i.imgur.com/5BnTWP0.png

Despite the error message, the program saves and runs just fine. I
have Racket version 7.1.0.9.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Loggers that don't prepend?

2018-11-26 Thread Shu-Hung You
I think it depends on the code that logs the message, not the logger.
In the log-message function, the topic and the prefix-message?
arguments together control whether the message will be prefixed by the
topic and ": " or not.
On Mon, Nov 26, 2018 at 5:00 PM David Storrs  wrote:
>
> Is there a way to have a logger that prints the message I give it without 
> modification?  (i.e. without prepending the topic or anything else)
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Obtain use-site source information

2018-11-21 Thread Shu-Hung You
Thanks! However, I am trying to avoid changing USE. The trouble is
that there are too many macros using X that I don't understand, and
these macros themselves are more than one layers deep. It is nearly
impossible to thread the syntax property through the macros.On Wed,
Nov 21, 2018 at 7:30 PM Matthew Butterick  wrote:
>
> (PS ignore "at L ..." — apparently `gensym` in RacketCS is broken.)
>
> > ;; Result:
> > ;; "at L (unsaved-editor:24.3) ; #f #f"
> > ;; "at L (unsaved-editor:25.3) ; #f #f"
> > ;; "at L (unsaved-editor:26.0) ; #f #f"
> > ;; "at L (unsaved-editor:27.0) ; #f #f"
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] Obtain use-site source information

2018-11-21 Thread Shu-Hung You
I have a macro (let's called it X) that generates unique symbols at
all its uses. I need all its uses to be distinguishable from each
other.

(define-syntax X
  (syntax-parser
[(_ stx)
 (define label (gensym 'L))
 #`(log-error "at ~a (~a) ; ~a ~a"
 '#,label
 (quote-srcloc-string #,#'stx)
 '#,(current-module-declare-name)
 '#,(current-module-declare-source))]))

X is also used in many other macros:

(define-simple-macro (USE)
  (void (vector (X 'USE ;; A

(X (or 'here #f))
(X 'there)
(USE) ;; B
(USE) ;; C

It works, but it would be better if (X 'USE) can log information about
its uses at B and C in addition to the source location A for debugging
purpose. If I don't want to change the implementation of USE, is there
a way for X to obtain the source information of B and C?

Currently, the only information I can get is the client module that
uses USE, obtained by checking (current-module-declare-name) at
expansion time in X.

Shu-Hung

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] One macro -> N defined functions

2018-11-20 Thread Shu-Hung You
The begin form can encapsulate multiple definitions like this:

(require (for-syntax racket/sequence
 racket/syntax)
 syntax/parse/define)

(define-simple-macro (define-asserts predicate:id ...)
  #:with (assert-name ...)
  (for/list ([id (in-syntax #'(predicate ...))])
(format-id this-syntax "assert-~a" (syntax-e id)))
  (begin
(define (assert-name response)
  (assert-lines response predicate))
...))

Note that format-id needs to use this-syntax (from syntax parse,
referring to the syntax object passed to the current syntax
transformer) to obtain the right lexical context.

On Tue, Nov 20, 2018 at 8:26 AM Brian Adkins  wrote:
>
> I'm just beginning to dig in to Racket macros, so forgive the newbie question 
> :) Is it possible to create a macro that will result in multiple functions 
> being defined?
>
> I have a bunch of predicate functions, and I'm creating a parallel set of 
> assert functions that look like the following:
>
> (define (assert-at-home-page response)
>   (assert-lines response at-home-page?))
>
> (define (assert-at-signon-page response)
>   (assert-lines response at-signon-page?))
>
> ...
>
> It would be trivial to define a macro to create a single assert more nicely 
> than the above, but it would be nice to be able to use something like:
>
> (define-asserts at-home-page? at-inquiry-menu? at-signon-page? ... )
>
> All of the macros I've experimented with thus far deal with a single form.
>
> Thanks,
> Brian
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Is there a way to eval a custom language from inside a module... without instantiating modules multiple times?

2018-11-16 Thread Shu-Hung You
On Fri, Nov 16, 2018 at 12:43 PM Andrew Wilcox  wrote:
>
> I'd like to be able to eval a custom language from inside a module... without 
> instantiating modules multiple times.
>
> With the help of Matthew Butterick, I've gotten this far:
>
> ; runtime.rkt
> #lang racket
>
>
> (printf "This is runtime.rkt~n")
>
>
>
> ; example.rkt
> #lang racket
>
> (require "runtime.rkt")
>
> (provide foo)
>
> (printf "This is example.rkt~n")
>
> (define-syntax foo
>   (syntax-rules ()
> ((foo)
>  (printf "foo!~n"
>
>
>
> ; eval-example.rkt
> #lang racket
>
> (require racket/runtime-path)
>
> (require "runtime.rkt")
>
> (provide eval-example)
>
> (define-runtime-path example "example.rkt")
>
> (define example-namespace (make-base-empty-namespace))
>
> (parameterize ((current-namespace example-namespace))
>   (namespace-require example))
>
> (define (eval-example code)
>   (parameterize ((current-namespace example-namespace))
> (eval code)))
>
>
> however this instantiates runtime.rkt twice:
>
> $ racket eval-example.rkt
> This is runtime.rkt
> This is runtime.rkt
> This is example.rkt
>
>
> which turns out to be bad (for example, if I define a struct in the runtime, 
> I end up having a different struct types).  I want there to be a single copy 
> of the runtime.rkt module (much like if I had said (require "runtime.rkt") 
> from two different modules).
>
> What I want to do is rather simple (I hope): define a custom language in a 
> module such as example.rkt, and then be able to eval that language.
>
> Is there a way to do this?
>

Because eval-example.rkt creates a new, independent namespace and runs
example.rkt in the new namespace, the modules eval-example.rkt and
example.rkt will have different instantiations of runtime.rkt. The
workaround, therefore, is to share the instantiation of runtime.rkt.
However, sharing also implies that eval-example.rkt could be affected
by example.rkt unexpectedly.

There are two ways to share the instantiation of runtime.rkt.

1. Keep the new namespace, but use namespace-attach-module to attach
runtime.rkt from eval-example.rkt to example-namespace before
(namespace-require example).

;; eval-example.rkt
> (define-runtime-module-path runtime "runtime.rkt")
> (define-namespace-anchor here)
> (define host (namespace-anchor->namespace here))
> (parameterize ((current-namespace example-namespace))
>   (namespace-attach-module host runtime)
>   (namespace-require example))

2. Just use the same namespace as eval-example.rkt

;; eval-example.rkt
> (define-namespace-anchor here)
> (define example-namespace (namespace-anchor->namespace here))

Both methods need to be used with care.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Re: reporting contract violations in executable programs

2018-11-01 Thread Shu-Hung You
Thanks for catching this! This is a bug in the setup/dirs library,
which the contract system transitively depends on to compute the path
in the error message. I opened a pull request and let's see how it
goes (#2352).
On Thu, Nov 1, 2018 at 5:23 PM Alex Harsanyi  wrote:
>
>
>
> On Thursday, November 1, 2018 at 7:38:29 PM UTC+8, Alexander McLin wrote:
>>
>> I’m a little confused here, to me it looks like the second contract 
>> violation is completely different from the first one.
>
>
> My program is only seven lines of code and does not call `build-path`.  Also, 
> if I fix the incorrect call to `foo` and rebuild the executable, the 
> `build-path` contract violation is no longer reported and the program runs 
> fine.  You might wan to actually build the executable and run it using the 
> instructions I provided, to understand what I am trying to explain.
>
> #lang racket
> (require racket/contract)
>
> (define/contract (foo n)
>   (-> integer? any/c)
>   (printf "foo: ~a~%" n))
>
> (module+ main
>   (foo "hello"))
>
> This is just a small example that illustrates the problem -- I have an actual 
> application which is built into an executable and, whenever there is a 
> contract violation error reported, regardless of what the contract violation 
> is about, always the `build-path` contract violation shows up.  At first, I 
> was puzzled by this, but now, I have learned that when I see a build path 
> contract error, I try to run the application in un-compiled mode (is there a 
> better term?) and try to reproduce the issue -- but this is not always easy 
> with complex applications.
>
> Alex.
>
>>
>> You were expecting `foo` to raise a contract violation but in your 
>> executable example it appears that contract violation is being raised by the 
>> `build-path` function not `foo`.
>>
>> Maybe it’s a entirely different error?
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] confusion about call-with-current-continuation

2018-10-26 Thread Shu-Hung You
Because applying the continuation captured by Racket's
call-with-current-continuation will *replace* existing continuations.
Therefore the exception handler is removed. To obtain a continuation
that will only *extend* the current continuation, use
call-with-composable-continuation.

(Another way to get "div by 0" is to wrap the call to saved-k in a
prompt via call-with-continuation-prompt so saved-k would not remove
the portion of continuation that installs the handler.)
On Fri, Oct 26, 2018 at 3:53 AM  wrote:
>
>
> Thanks Shu-hung.
>
> So here is my understanding:
>
> #lang racket
>
> (begin
>
>   (define saved-k #f) ; wrapped in "prompt 1"
>
>   (+ 1 (call/cc
> (lambda (k)
>   (set! saved-k k)
>   0))) ; wrapped in "prompt 2"
>
>   (println 'hello) ; wrapped in "prompt 3"
>
>   (saved-k 100) ; wrapped in "prompt 4"
>
>   (println 'hello2) ; wrapped in "prompt 5"
>
>   )
>
> When we call (saved-k 100), control flow jump to the continuation saved 
> before, but it still in "prompt 4".
> After "prompt 4" all finished, the next prompt is "prompt 5" (prompt is also 
> a continuation, but marked) , so print 'hello2.
> Then all end.
>
> Everything is fine.
>
> But what about this code:
>
> #lang racket
>
> (begin
>
>   (define saved-k #f) ; wrapped in "prompt 1"
>
>   (/ 1 (call/cc
> (lambda (k)
>   (set! saved-k k)
>   1))) ; wrapped in "prompt 2"
>
>   (println 'hello) ; wrapped in "prompt 3"
>
>   (with-handlers ([exn:fail:contract:divide-by-zero?
>(lambda (exn) (println "div by 0"))])
> (saved-k 0)) ; wrapped in "prompt 4"
>
>   (println 'hello2) ; wrapped in "prompt 5"
>
>   )
>
> Since the continuation executed in "prompt 4", why I can not print "div by 0" 
> ?
>
>
> On Friday, October 26, 2018 at 3:57:57 AM UTC+8, Shu-Hung You wrote:
>>
>> FWIW here's the part in the document that could be helpful:
>>
>> 1. The section in the Guide that talks about the concept of prompts
>> and their usage in the continuation in Racket:
>> https://docs.racket-lang.org/guide/prompt.html
>> The prompt is kind of like a mark on the continuations that lets the
>> control operators find the portion of continuations they want to
>> manipulate.
>>
>> 2. About your original question (why (print 'hello) isn't captured),
>> there are two things happening here:
>>
>> 2a. Begin is a special syntactic form. It does not just mean
>> evaluating a sequence of expressions in order. When used at certain
>> contexts such as top-level (module-level) context, begin splices the
>> forms it contains to the surrounding context. The last paragraph in
>> the guide ( https://docs.racket-lang.org/guide/begin.html ) briefly
>> talked about it. The reference (
>> https://docs.racket-lang.org/reference/begin.html#(form._((quote._~23~25kernel)._begin))
>> ) made it explicit that the forms
>> (begin expr expr ...)   and
>> (begin form form ...)
>> are different.
>>
>> As an example, in the following module, with or without begin makes no
>> difference at all. The subforms are spliced to the module-level
>> context:
>>
>> #lang racket
>>
>> (define (even??? x) (odd??? (- x 1)))
>>
>> ;; At module-level context, this begin works as if the
>> ;; program were just written directly without begin:
>> ;; (displayln ...)
>> ;; (define (odd??? ...
>> (begin
>> (displayln "No difference")
>> (define (odd??? x) (odd? x)))
>>
>> (odd??? 9)
>> (even??? 8)
>>
>> This, combined with the following reason (2b) is why your code didn't
>> work as expected.
>>
>> 2b. The evaluation of module-level expressions and definitions are
>> implicitly wrapped in a prompt. That is, for a module
>>
>> #lang racket
>>
>> expr1
>> (define def2 expr2)
>> expr3
>> expr4
>> (define def5 expr5)
>> ...
>>
>> the evaluation of each expr is implicitly wrapped by the default
>> prompt as if it were evaluated using:
>>
>> procedure instantiate a module M:
>> for each module-level expression/definition EXPR do:
>>   with DEFAULT_PROMPT:
>>   result = eval(EXPR)
>>   ...
>>
>> The control operators (e.g. call/cc and abort) by default looks for
>> the default prompt. This effectively delimits the control effect of
&g

Re: [racket-users] confusion about call-with-current-continuation

2018-10-25 Thread Shu-Hung You
FWIW here's the part in the document that could be helpful:

1. The section in the Guide that talks about the concept of prompts
and their usage in the continuation in Racket:
https://docs.racket-lang.org/guide/prompt.html
The prompt is kind of like a mark on the continuations that lets the
control operators find the portion of continuations they want to
manipulate.

2. About your original question (why (print 'hello) isn't captured),
there are two things happening here:

2a. Begin is a special syntactic form. It does not just mean
evaluating a sequence of expressions in order. When used at certain
contexts such as top-level (module-level) context, begin splices the
forms it contains to the surrounding context. The last paragraph in
the guide ( https://docs.racket-lang.org/guide/begin.html ) briefly
talked about it. The reference (
https://docs.racket-lang.org/reference/begin.html#(form._((quote._~23~25kernel)._begin))
) made it explicit that the forms
(begin expr expr ...)   and
(begin form form ...)
are different.

As an example, in the following module, with or without begin makes no
difference at all. The subforms are spliced to the module-level
context:

#lang racket

(define (even??? x) (odd??? (- x 1)))

;; At module-level context, this begin works as if the
;; program were just written directly without begin:
;; (displayln ...)
;; (define (odd??? ...
(begin
(displayln "No difference")
(define (odd??? x) (odd? x)))

(odd??? 9)
(even??? 8)

This, combined with the following reason (2b) is why your code didn't
work as expected.

2b. The evaluation of module-level expressions and definitions are
implicitly wrapped in a prompt. That is, for a module

#lang racket

expr1
(define def2 expr2)
expr3
expr4
(define def5 expr5)
...

the evaluation of each expr is implicitly wrapped by the default
prompt as if it were evaluated using:

procedure instantiate a module M:
for each module-level expression/definition EXPR do:
  with DEFAULT_PROMPT:
  result = eval(EXPR)
  ...

The control operators (e.g. call/cc and abort) by default looks for
the default prompt. This effectively delimits the control effect of
each module-level expression and therefore the call/cc in your code
will not capture the println portion.

This behavior is described in the reference about how the body of a
module is evaluated, starting from the paragraph ``A module body is
executed only when the module is explicitly instantiated ...''
https://docs.racket-lang.org/reference/module.html

On Thu, Oct 25, 2018 at 2:00 PM  wrote:
>
>
> About (+ 1 (prompt (* 2 (call/cc (lambda (k) (set! x k) 2)
>
> 1. "prompt" form does not exist in racket.
> It is a procedure application or special form ?
>
> 2. assume this procedure or special form exists to construct a prompt.
>
> (+ 1 (prompt (* 2 (call/cc (lambda (k) (set! x k) 2)
>
> After the (lambda (k) ...) evaluated, value of k is (* 2 []), then I call
> (k 0) ; < When does the control flow come back here?
>
> (k 0) ---jump to--> (* 2 []), and then?
>
> What happens after (*2 0) ? What is the continuation of (*2 0)?
>
>
> On Friday, October 26, 2018 at 2:11:43 AM UTC+8, Joao Pedro Abreu De Souza 
> wrote:
>>
>> well, let's go by parts :
>>
>> 1) call/cc in principle will capture the complete continuation of a 
>> expression, right? Delimited continuation will capture ... welll, delimited 
>> continuations. But delimited by what? By a prompt.
>> In a delimited contninuation style(not really, but I dont want to mix 
>> functions), we will do something like (+ 1 (prompt (* 2 (call/cc (lambda (k) 
>> (set! x k) 2)
>>
>> this will set x with (* 2 []), because delimited capture from prompt.  
>> call/cc in racket works in a similar way, if around the most extern s-exp 
>> exists a prompt.
>>
>> 2) well, when I dont know exactly why begin dont work and lambda do, but I 
>> have a clue : if you do (syntax->datum (expand '(begin (print "hi") (print 
>> "hello" in drracket, you will receive
>> '(begin (#%app print '"hi") (#%app print '"hello"))
>>
>> and if you do (syntax->datum (expand '((lambda () (print "hi") (print 
>> "hello") you will receive '(#%app (lambda () (#%app print '"hi") (#%app 
>> print '"hello")))
>>
>> Probably, as begin dont is involved in a #%app, he dont is invoked with a 
>> prompt. But this is just speculation of my part.
>>
>> Em qui, 25 de out de 2018 às 14:13,  escreveu:
>>>
>>> Thank Joao
>>>
>>> I change my code like this:
>>>
>>> #lang racket
>>>
>>>
>>> ((lambda ()
>>>
>>>   (define saved-k #f)
>>>
>>>   (println (+ 1 (call/cc
>>> (lambda (k) ; k is the captured continuation
>>>   (set! saved-k k)
>>>   0
>>>
>>>   (println 'hello)
>>>
>>>   (saved-k 100)
>>>
>>>
>>>   ))
>>>
>>> Now it works as I expected.
>>>
>>> But why?
>>>
>>> "begin" special form packages a sequence of expressions into a single 
>>> expression. After compiled, it should be continuation-passing style.
>>>
>>> "lambda" 

Re: [racket-users] handin-server: reader used in checker modules

2018-10-17 Thread Shu-Hung You
On Wed, Oct 17, 2018 at 1:12 PM Jordan Johnson  wrote:
>
>
> On Oct 17, 2018, at 10:35, Matthias Felleisen  wrote:
>
> (check-expect (+ 10 .25) 10.25)
>
> errors with check-expect’s message about not comparing inexact numbers, but 
> in DrRacket+BSL the decimals are treated as exact numbers.
>
> What do I need to change in the checker, in order to obtain the same numeric 
> behavior as in DrRacket?
>
> Set read-decimal-as-inexact might solve the problem.
>
>
> Progress! But not completely solved. By adding
>
> (read-decimal-as-inexact #f)
>
> to the checker module, I now don’t get the check-expect error. Instead, I’m 
> seeing
>
> submit error: your code failed a test: (hour-angle 12 20 30) evaluated to 
> 41/4, expecting 10.25
>
>
> produced by the checker line
>
> (!test (hour-angle 12 20 30) 10.25)
>

Would it help if in the check module you use `=' as the equality test,
or specify #e10.25 instead?

> where hour-angle computes exactly.
>
> So, what aspect of the language config would be responsible for 41/4 not 
> equaling 10.25?
>
> Best,
> Jordan
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Racket-on-Chez snapshots

2018-10-01 Thread Shu-Hung You
Here! http://www.cs.utah.edu/~mflatt/racket-on-chez-jan-2018/
Also a few days algo there were some more updates at RacketCon and
Scheme Workshop.
On Mon, Oct 1, 2018 at 1:08 PM Brett Gilio  wrote:
>
>
> Philip McGrath writes:
> > In light of
> > the promising outlook for Chez replacing the current Racket VM
> > in the
>
> > -Philip
>
>
> Hey, could you provide a resource with more information on Chez
> possibly
> replacing the Racket VM? I haven't been keeping up to date on
> this.
>
> --
> Brett M. Gilio
> Free Software Foundation, Member
> https://gnu.org/software/guix | https://emacs.org
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] MIT/Chicken/Chibi Scheme style ir-macro-transformer in Racket

2018-08-29 Thread Shu-Hung You
I should've been clear that the loop example was taken from the
Chicken scheme wiki. Same for the while example mentioned in the
email:
https://wiki.call-cc.org/man/4/Macros#ir-macro-transformer

Using the syntax->datum here would drop lexical information though; if
the syntax object given to the macro has lexical context other than
the use-site of the macro, binding information will be lost.

(define-syntax (use-loop stx)
  (syntax-case stx ()
[(_ body) #'(loop (displayln "loop") body (exit))]))

(let ([i 0]) (loop (displayln "loop") (displayln i) (exit)))
(let ([i 0]) (use-loop (displayln i)))



On Wed, Aug 29, 2018 at 4:32 PM, t791bc via Racket Users
 wrote:
> Thanks for the responses. In case anybody is interested, I came up with the
> following implementation. Since (at least in this simple implementation)
> there is an obvious symmetry between explicit renaming and implicit renaming
> I added the er-macro-transformer also. They seem to work correctly. One
> minor difference to the ir-macro-transformer in Chicken though is that
> parameters also need to be injected (which kind of logically makes sense).
>
> I am not exactly sure whether datum->syntax and syntax->datum go through the
> entire expression but if they do, the implementation will be very
> inefficient. (If anybody knows more on that, I would be interested.)
>
> Implementation:
>
> #lang racket
>
> (provide (for-syntax ir-macro-transformer er-macro-transformer))
>
> (begin-for-syntax
>   (require (for-syntax (only-in racket/base lambda syntax with-syntax)))
>   (define-syntax ir-macro-transformer
> (lambda (stx)
>   (with-syntax ([(_ proc) stx])
> #'(lambda (x)
> (datum->syntax #'proc (proc (syntax->datum x) (lambda (v)
> (datum->syntax x v
>   (define-syntax er-macro-transformer
> (lambda (stx)
>   (with-syntax ([(_ proc) stx])
> #'(lambda (x)
> (datum->syntax x (proc (syntax->datum x) (lambda (v)
> (datum->syntax #'proc v)
>
> Examples:
>
> ; loop example from Shu-Hung's post is now working as expected
>
> (define-syntax loop
>   (ir-macro-transformer
>(lambda (expr inject)
>  (let ((body (cdr expr)))
>`(call-with-current-continuation
>  (lambda (,(inject 'exit))
>(let f () (begin .,(inject body)) (f   ; notice the
> (inject body) here... dropping the inject will break the code
>
> ;=> 543210
>
> ; the following suggests that the lexical environments work as they should
>
> (let ([x 1]
>   [y 2])
>   (swap! x y)
>   x)
>
> => 2
>
> (define t 3)
>
> (define-syntax tripple
>   (ir-macro-transformer
>(lambda (expr inject)
>  (let ([a (cadr expr)])
>`(* t ,(inject a))
>
> (let ([t 29]
>   [* -])
>   (tripple 2))
>
> ;=> 6
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] MIT/Chicken/Chibi Scheme style ir-macro-transformer in Racket

2018-08-29 Thread Shu-Hung You
I think the following program illustrates the idea, though it doesn't
really work:

#lang racket

(begin-for-syntax
  (define (syntax-pair->cons stx)
(define datum (syntax-e stx))
(cond
  [(list? datum)
   (map syntax-pair->cons datum)]
  [(pair? datum)
   (cons (syntax-pair->cons (car datum))
 (syntax-pair->cons (cdr datum)))]
  [else stx]))

  (define (ir-macro-transformer proc)
(lambda (stx)
  (define transformed-s-expr
(proc (syntax-pair->cons stx)
  (λ (id) (datum->syntax stx id
  (datum->syntax #'here transformed-s-expr ;; hack

(define-syntax loop
  (ir-macro-transformer
   (lambda (expr inject)
 (let ((body (cdr expr)))
   `(call-with-current-continuation
 (lambda (,(inject 'exit))
   (let f () ,@body (f

(let ([i 0])
  (loop
   (printf "i = ~a\n" i)
   (set! i (+ i 1))
   (when (>= i 5)
 (exit 'ok

Syntax objects are the representation of syntaxes used in expansion
and compilation. Racket doesn't just use quoted expressions since the
expander and the compiler need to keep track of lexical information,
source location and other properties. The form #' and #` are
constructors of syntax objects that take templates and produce the
syntax objects with the desired shape, just like ' and ` are
constructors of quoted s-expressions.

If you want to provide a function that manipulates lists and symbols
as a transformer, ir-macro-transformer would at least need to be a
function that maps between syntax objects and quoted expressions. Such
maps are imperfect though.

One problem I found with the above program is that `inject' doesn't
have the desired lexical context, so the while example does not work.

phase 1 phase 0
 + syntax object (instead of quoted s-expression)
 |
transformer
(lambda functions bound
 using define-syntax)
 |
 +---> syntax object

On Wed, Aug 29, 2018 at 7:25 AM, Philip McGrath
 wrote:
> For future reference, you should try the wonderful macro stepper in
> DrRacket, which shows you exactly how expansion happens. It can even handle
> buggy, non-terminating examples like the version of `test` you wrote.
> -Philip
>
>
> On Wed, Aug 29, 2018 at 7:20 AM Philip McGrath 
> wrote:
>>
>> I'm not familiar with how `ir-macro-transformer` is supposed to work, but
>> your macro is currently fails for essentially the same reason as:
>> (define-syntax (diverge stx)
>>   stx
>>
>> The `expr` given to `test` is a syntactic list beginning with the
>> identifier `test`, so including it in the output triggers another expansion
>> of `test`, infinitely.
>>
>> -Philip
>>
>>
>> On Wed, Aug 29, 2018 at 7:06 AM t791bc via Racket Users
>>  wrote:
>>>
>>> Hi,
>>>
>>> while syntax-case has some advantages, I was trying to implement a
>>> Chicken style ir-macro-transformer in Racket so that I can write macros that
>>> will run both on Racket and systems like Chicken/Chibi Scheme.
>>>
>>> My first attempt was as follows:
>>>
>>> (begin-for-syntax
>>>   (require (for-syntax racket/base))
>>>   (define-syntax (ir-macro-transformer stx)
>>> (syntax-case stx ()
>>>   [(_ ir-trans)
>>> #'(lambda (x)
>>> #`(ir-trans #,(syntax->datum x) 23))])))
>>>
>>> (define-syntax test
>>>   (ir-macro-transformer
>>>(lambda (expr inject)
>>>expr)))
>>>
>>> The result was "Background expansion terminated abnormally (out of
>>> memory)". If the #, is taken out I get an error that x is unbound. As should
>>> be obvious from the above,  I find it hard to reason about all those syntax
>>> effects - which only makes me want the ir-macro-transformer more despite all
>>> its shortcomings.
>>>
>>> Any help would be highly appreciated.
>>>
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "Racket Users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send an
>>> email to racket-users+unsubscr...@googlegroups.com.
>>> For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Where to put scribblings in 'multi package?

2018-08-29 Thread Shu-Hung You
The gui-lib might be an example. It provides modules spanning
different collections such as racket/gui, framework/ and mrlib/.

https://github.com/racket/gui/tree/master/gui-lib

On Wed, Aug 29, 2018 at 7:13 AM, Erich Rast  wrote:
> On Wed, 29 Aug 2018 06:46:49 -0500
> Philip McGrath  wrote:
>
>
>> You don't need a multi-collection package to do this. If your
>> structure is:
>>
>> appy/
>> |
>> |--info.rkt
>> |--main.rkt
>> |--gui.rkt
>> |--…
>>
>> Then `(require appy)` will import "main.rkt" and `(require appy/gui)`
>> will import "gui.rkt".
>
> Oh, that's very useful info I didn't know that. I thought this
> possibility is exactly the purpose of multi-collection packages. I'll
> make it flat again ASAP.
>
> Out of curiosity, if it's not the above selective importing, what *is*
> the main use case for multi-collection packages?
>
> Best,
>
> Erich
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] In Redex, how to to specify mutually-recursive bindings (#:refers-to)?

2018-08-23 Thread Shu-Hung You
Is it possible to specify mutually-recursive scope in Redex without an
extra layer of nesting expression? I found this example for letrec:

https://github.com/racket/redex/blob/master/redex-examples/redex/examples/letrec.rkt#:34
34  #:binding-forms
...
37  (letrec ([x e_x] ...) #:refers-to (shadow x ...) e_body
#:refers-to (shadow x ...))

But this binding specification for letrec does not work for `define' forms:

expr ::=  (λ (x_arg ...) (define x_def expr_def) ... expr_body)

I wish to allow (expr_def ...) to refer to (x_def ...) and that (x_def
...) will shadow (x_arg ...), but placing `#:refers-to (shadow x_def
...)' next to expr_def does not work. The workaround I found either
requires an extra nesting level or failed for the first define form.
How to solve this?

;; does not work
#:binding-forms
(λ (x_arg ...)
  (define x_def expr_def) #:refers-to (shadow x_def ... x_arg ...) ...
  expr_body #:refers-to (shadow x_def ... x_arg ...))

;; workaround 1, works mostly but failed for the first definition
#:binding-forms
(λ (x_arg ...)
  (define x_def expr_def)
  #:...bind (vars-defined
 (shadow x_def vars-defined)
 (shadow x_def vars-defined))
  expr_body #:refers-to (shadow vars-defined x_arg ...))

;; workaround 2, requires an extra nesting level
(expr ::=  (λ (x_arg ...) (begin (define x_def expr_def) ... expr_body)))
#:binding-forms
(λ (x_arg ...)
  (begin
   (define x_def expr_def) ...
   expr_body)  #:refers-to (shadow x_def ... x_arg ...))

;; the term being tested:
(term
 (λ (x)
   (define f (λ (tt) g))
   (define g (λ (tt) h))
   (define h (λ (tt) f))

   (define x (λ (tt) x))

   g))

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] How to handle define forms in a scribble-like language

2018-08-17 Thread Shu-Hung You
I would try make-wrapping-module-begin too. Basically, it wraps all
module-level forms that "calculates something" with the syntax object
you gave it. For example, the following program

;; some-language.rkt
#lang racket

(provide (except-out (all-from-out racket)
 #%module-begin)
 (rename-out
  [mb-module-begin #%module-begin]))

(require "some-module-that-provides-add-content.rkt"
 syntax/wrap-modbeg
 (for-syntax syntax/parse))

(define-syntax acc-module-begin
  (make-wrapping-module-begin #'add-content!))

(define-syntax mb-module-begin
  (syntax-parser
[(_ module-level-expr:expr ...)
 #'(acc-module-begin
module-level-expr ...)]))

will be able to transform the code

#lang s-exp "some-language.rkt"
"abcdefg\n"
(define y 5)
"hijk\n"
y

into something like:

#lang s-exp "some-language.rkt"
(add-content! "abcdefg\n")
(define y 5)
(add-content! "hijk\n")
(add-content! y)

If add-content! saves all values in a global variable, the whole
content can be extracted later (after module-level-expr ...).

On Fri, Aug 17, 2018 at 2:23 PM, Vityou  wrote:
> Thanks for the example.  I'm still somewhat new to racket, so I may have to 
> study the example for a while before I understand it.  The 
> `make-wrapping-module-begin` that Alexis mentioned seems to do something 
> similar, so I may end up using that due to it's simplicity.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Do I need macros to flag unbound identifiers as failing unit tests?

2018-08-11 Thread Shu-Hung You
Would convert-syntax-error and convert-compile-time-error work? Sure
they are macros, but wrapped up in a nice way.

https://docs.racket-lang.org/syntax/macro-testing.html


On Sat, Aug 11, 2018 at 11:00 AM, Sage Gerard  wrote:
> Hi all,
>
> Still working the koans project and am hitting a design snag. My expected UX
> is that you clone the repo, run racket koans/all.rkt, and then see nothing
> but failing unit tests for you to fix.  But since some exercises have
> unbound module identifiers or related errors, an abort prevents rackunit
> from printing a full report.
>
> "Well Sage, why don't you write tests that actually run?" Great question!
> But if you look at that linked module you can see what I think is a clear,
> concise exercise where checking in unbound identifiers seemed reasonable at
> the time. I wanted someone to see that Racket was generating all of these
> identifiers and write the corresponding struct definition.
>
> After wresting with various combinations of (with-handlers), (check-exn),
> (fail), (module), and (call/prompt), I found that modules too picky about
> where they are defined for me to simply catch an unbound identifier error,
> and I wasn't liking how much noise I might be introducing in the koan
> itself.
>
> I'm starting to think writing these kind of exercises in a friendly way is
> only possible with macros, but before I go that far, is it possible for me
> to catch a module-level unbound identifier error and print a rackunit
> failure outright without distracting the student?
>
> I'd appreciate feedback on the design here too, since I have to pick a
> direction to handle this kind of problem project-wide.
>
> Sage
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Re: Question about style

2018-08-11 Thread Shu-Hung You
For small expressions it probably does not matter, but suitably naming
intermediate expressions is definitely a good approach as it
`explains' the code. Also, replacing let* by define can reduce nesting
level. These 2 points are suggested in the style guide 4.2 and 4.4:

https://docs.racket-lang.org/style/Choosing_the_Right_Construct.html


On Sat, Aug 11, 2018 at 9:30 AM, Wolfgang Hukriede  wrote:
> My advice would be to follow your own taste. But drop the brackets.
>
>
> On Saturday, August 11, 2018 at 4:11:19 PM UTC+2, Robert Heffernan wrote:
>>
>> Dear all,
>>
>> I am new to Racket and only slightly less new to scheme & scheme-like
>> languages.
>>
>> I have noticed myself often doing something like the following:
>>
>> (define (foo x)
>>   (let* ([y (f x)]
>>  [z (g y)]
>>  [p (h z)])
>> (bar p)))
>>
>> Which could, of course, be written as
>>
>> (define (foo x)
>>   (bar (h (g (f x)
>>
>> Here's an example from something I was just working on:
>>
>> (define (get-data input)
>>   (let* ([url-string (construct-url input)]
>>  [url (string->url url-string)]
>>  [port (get-pure-port url)])
>> (read-json port)))
>>
>> which, again, could be written as:
>> (define (get-data input)
>>   (read-json (get-pure-port (string->url (construct-url input)
>>
>> My question is: is the way I'm writing things considered to be bad
>> style?  It feels like a hangover from more imperative-style programming
>> & the inclination to do one thing "per line".  On the other hand, it
>> often helps readability.
>>
>> It might be, of course, that both versions amount to the same thing
>> after the interpreter has been at them.
>>
>> Thanks and regards,
>> Bob Heffernan
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] How to limit memory usage and raise out-of-memory error?

2018-08-10 Thread Shu-Hung You
Cool! That does the job. Thank you.

On Fri, Aug 10, 2018 at 3:57 PM, Matthew Flatt  wrote:
> For the second part, use `thread/suspend-to-kill` to create a thread
> that is merely suspended when its custodian is shut down, and then you
> can use `(continuation-marks thread-id)` to get the thread's
> continuation marks at the point where it was suspended.
>
> You'll need to wait until either the thread is terminated or the
> custodian is shutdown, instead of waiting until the thread terminates.
> Use a custodian box (for the same custodian) as a synchronizable event
> for custodian shutdown.
>
> At Fri, 10 Aug 2018 15:27:07 -0500, Shu-Hung You wrote:
>> I'm running a thread with memory limit using custodian-limit-memory.
>> How do I reliably detect whether the thread I'm running was terminated
>> normally or aborted by custodian shutdown? Plus, is it possible to
>> obtain the context at the time the memory limit was exceeded?
>>
>> I can think these two:
>>
>> 1. Use a channel to indicate normal termination, or
>> 2. detect whether the custodian had been shut down.
>>
>> Both methods address the first question but not the second question.
>> Any pointers?
>>
>> Best,
>> Shu-Hung
>>
>> (define TIMEOUT 60)
>> (define MEMORY-LIMIT (* 2 1024 1024 1024))
>>
>> (parameterize ([current-custodian (make-custodian)])
>>   (custodian-limit-memory (current-custodian) MEMORY-LIMIT)
>>   (define thread-id
>> (thread (λ ()
>>   (displayln "This displayln probably takes lots of 
>> memory"
>>   (define ended? (sync/timeout/enable-break TIMEOUT thread-id))
>>   (unless ended? (break-thread thread-id 'terminate))
>>   (thread-wait thread-id)
>>   (when (custodian-shut-down? (current-custodian))
>> ;; The context here is not the right one and the exception is not
>> ;; raised in the right thread
>> (raise (exn:fail:out-of-memory "Out of memory"
>> (current-continuation-marks)))
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Racket Users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to racket-users+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] How to limit memory usage and raise out-of-memory error?

2018-08-10 Thread Shu-Hung You
I'm running a thread with memory limit using custodian-limit-memory.
How do I reliably detect whether the thread I'm running was terminated
normally or aborted by custodian shutdown? Plus, is it possible to
obtain the context at the time the memory limit was exceeded?

I can think these two:

1. Use a channel to indicate normal termination, or
2. detect whether the custodian had been shut down.

Both methods address the first question but not the second question.
Any pointers?

Best,
Shu-Hung

(define TIMEOUT 60)
(define MEMORY-LIMIT (* 2 1024 1024 1024))

(parameterize ([current-custodian (make-custodian)])
  (custodian-limit-memory (current-custodian) MEMORY-LIMIT)
  (define thread-id
(thread (λ ()
  (displayln "This displayln probably takes lots of memory"
  (define ended? (sync/timeout/enable-break TIMEOUT thread-id))
  (unless ended? (break-thread thread-id 'terminate))
  (thread-wait thread-id)
  (when (custodian-shut-down? (current-custodian))
;; The context here is not the right one and the exception is not
;; raised in the right thread
(raise (exn:fail:out-of-memory "Out of memory"
(current-continuation-marks)))

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] bf "module: initial import is not a well-formed module path"

2018-08-09 Thread Shu-Hung You
On Thu, Aug 9, 2018 at 3:42 PM, Zeta Convex  wrote:
>
>
> On Thursday, 9 August 2018 21:34:16 UTC+1, Shu-Hung You wrote:
>>
>> Change the first few lines of lang/reader.rkt to:
>>
>> #lang s-exp syntax/module-reader
>> bf/language
>> #:read my-read
>> #:read-syntax my-read-syntax
>> ;; ...
>>
> Ah yes, that did it! Thanks!
>
>> And just install the entire directory as a package using raco pkg
>> install.
>
>
> I just installed it into my collects directory rather than using raco.
>
> I  typed my stuff in using his tutorial, rather than anything from planet.
>

Just a little clarification: installing the 'bf' directory locally
using the raco command does not involve interacting with the planet
system. All it does is recording the path in the local database and
compile every file in the directory. For example, I have a bunch of
local packages and downloaded packages installed:

$ raco pkg show
Installation-wide:
 Package Checksum  Source
 csv-reading 217c1ee293ee2...  catalog...eading
 custom-load 4e70205c29ab0...  catalog...m-load
 ...
 raco-find-collection00f0d3dbad025...  catalog...ection
 redex   3e069f3c6721e...  clone...th=redex
 rsvgc326fe1567908...  catalog...master
 scribble-abbrevsf207f11814f7e...  catalog...bbrevs
 scribble-math   063604d4a2b38...  catalog...th.git
 slideshow-repl  93246109d2dc4...  catalog...master
 soft-contract link...-contract


>>
>> I'm still getting application error after that, but I'm not sure what
>> went wrong.
>>
>
> Actually, everything is now working fine for me. Thanks for your help.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] bf "module: initial import is not a well-formed module path"

2018-08-09 Thread Shu-Hung You
Change the first few lines of lang/reader.rkt to:

#lang s-exp syntax/module-reader
bf/language
#:read my-read
#:read-syntax my-read-syntax
;; ...

And just install the entire directory as a package using raco pkg
install. This could take a while. If you want to make it faster, just
skip building the examples by adding (define compile-omit-paths
'("examples")) line to info.rkt before installing it:

$ pwd
/bf

$ git diff info.rkt
diff --git a/info.rkt b/info.rkt
index 5b4c3c1..4d681b9 100644
--- a/info.rkt
+++ b/info.rkt
@@ -10,4 +10,5 @@
 (define blurb
   '("bf: a brainf*ck compiler for Racket.  Includes a tutorial for
building a language in Racket."))
 (define release-notes
-  '((p "Final? release.")))
\ No newline at end of file
+  '((p "Final? release.")))
+(define compile-omit-paths '("examples"))

$ raco pkg install
Linking current directory as a package
raco setup: version: 7.0.0.8
...
raco setup: 2 rendering: /racket-index/scribblings/main/search.scrbl
raco setup: --- installing collections ---
raco setup: --- post-installing collections ---
$

I'm still getting application error after that, but I'm not sure what
went wrong.


On Thu, Aug 9, 2018 at 3:08 PM, Zeta Convex  wrote:
> I'm following the example from "F*dging up a Racket" at
>
> https://www.hashcollision.org/brainfudge/index.html
>
> I set up a project within ~/.racket/6.12/collects:
>
> .
> ├── bf
> │   ├── hello2.rkt
> │   ├── hello.rkt
> │   ├── lang
> │   │   └── reader.rkt
> │   ├── language.rkt
> │   ├── parser.rkt
> │   └── semantics.rkt
>
>
> I don't have a planet account, so I'm jiggling with the code.
>
> Should I be setting up new collections directly under
> ~/.racket/6.12/collects (because that's what I've done)?
>
> I've got the file reader.rkt as follows:
>
> #lang s-exp syntax/module-reader
> (require "../language.rkt")
> #:read my-read
> #:read-syntax my-read-syntax
>
> (require "../parser.rkt")
>
>
> (define (my-read in)
>   (syntax->datum (my-read-syntax #f in)))
>
> (define (my-read-syntax src in)
>   (parse-expr src in))
>
>
> The file hello2.rkt contains:
>
> #lang bf
> ++[><-]>.
>>++[>++<-]>+.
> +++..+++.>[>+++<-]>.
> <+++[><-]>.<+++[>+<-]>.
>>>.+++.--..>>+.
>
> When I try to run this file, I get the error message:
>
> module: initial import is not a well-formed module path in: (require
> "../language.rkt")
> Module Language: invalid language specification in: (require
> "../language.rkt")
>
> If I comment out reader.rkt:(require "../language.rkt") I get the message:
>
> syntax/module-reader: must specify either a module language, or #:language
>
> So I guess I need to specify a module language, but I don't know how to do
> that.
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] DrRacket prefs?

2018-05-24 Thread Shu-Hung You
Hi Stephen,

Running (find-system-path 'pref-file) in the REPL shows the path to
the preference file. Inside the file there's one line like:

(plt:framework-pref:framework:display-line-numbers #t)

I don't know if directly copying the pref file to another computer
would work but perhaps worth a try.


On Thu, May 24, 2018 at 12:28 PM, Stephen Foster
 wrote:
> Hi,
>
> I know how to hide/show line numbers from within DrRacket's GUI.  But is
> there a way to toggle this from the command line?  I have a few hundred
> computers with DrRacket installed, and I want to make them all show line
> numbers by default.  (I'd rather not do it by hand.)
>
> Is there a command I can run or a preferences file I could edit with a
> script?  Does anyone know where DrRacket stores user preferences like this?
>
> --Stephen
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Arity-error for Handin Checker

2018-05-12 Thread Shu-Hung You
Hi James,

If you use (check-deadline) in the checker, the config file needs to
contain the deadline of the assignment. If the deadline configuration is
not found, this error would show up. For example, in you have this config,

((active-dirs ("directoryA"))
 (inactive-dirs ...)
 (deadline
  (
   ("directoryA" (2019 3 24 23 59 59) 0)
   ...
   ))
 ...
 )

then in directoryA/checker.rkt, (check-deadline) will use 2019/03/24
23:59:59 as the deadline.


Related:

https://github.com/racket/handin/blob/master/handin-server/grading-utils.rkt#L127
https://github.com/racket/handin/blob/master/handin-server/grading-utils.rkt#L116-L118



On Sat, May 12, 2018 at 8:18 PM, James Yoo  wrote:

> Hi, everyone.
> Sorry if this is the wrong place to ask, but I've been having some issues
> using the checker service for the racket handin-server. I'm currently a TA
> trying to get some
> automating checking to work for the course I'm helping to teach :). I get
> the following error message:
>
>
> 
> Which I suspect is from a multiple-value function. I've also narrowed down
> the failing point to the function "check-deadlines" in the pre expression
> in checker.rkt. I'll be happy to provide the racket file if needed for
> further debugging.
>
> Again, I apologize in advance if this is the wrong place to ask, and thank
> you very much for your help!
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Problems with dynamic loading and `raco exe` executables

2018-05-07 Thread Shu-Hung You
#lang racket/load and (load PATH) are less idiomatic and more
low-level in Racket. I don't know how did racket/load and load
interact with ``raco exe'' but here's another way to make it work.
Everything is placed inside modules.


$ racket test.rkt
... ok ...

$ raco exe ++lib racket/base/lang/reader test.rkt
$ ./test
... ok ...

;; include.rkt
#lang racket/base
(provide new-config)
(define new-config "new-value")


;; test.rkt
#lang racket/base

(require racket/runtime-path
 ;; (for-syntax racket/base) is for expansion-time
 ;; evaluation in define-runtime-path
 (for-syntax racket/base))
(define *CHANGED-STRING* "old")

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

(define-runtime-path
  inc-path (string->path "include.rkt"))

(define (load-rc)
  (parameterize ([current-namespace ns])
(set! *CHANGED-STRING* (dynamic-require inc-path 'new-config

(load-rc)

(printf "~A~%" *CHANGED-STRING*)


On Mon, May 7, 2018 at 10:50 AM, Tony Fischetti
 wrote:
>
> This is some really great advice! Thanks!
>
> I'm still confused about why making an executable isn't working. Am I doing
> something wrong?
> Even if I choose the framework option for *this* project (it seems like a
> really helpful thing)
> I'd like to be able to distribute, for example, `.app` "executables" to
> MacOS users who
> just want stock configuration, etc...
> The existence of an `.app` executables is helpful in other ways, as well.
> For example,
> starting an application at startup, icons, etc...
>
>
>
> On Monday, May 7, 2018 at 11:16:32 AM UTC-4, Neil Van Dyke wrote:
>>
>> Regarding overriding globals, a Racket `parameter` is more idiomatic:
>> https://docs.racket-lang.org/reference/parameters.html
>>
>> And/or, you could load your config file as a module, like `info.rkt` is.
>>
>> You might find `dynamic-require` and friends interesting:
>>
>> https://docs.racket-lang.org/reference/Module_Names_and_Loading.html?q=dynamic-require#%28def._%28%28quote._~23~25kernel%29._dynamic-require%29%29
>>
>> For one different way to think about config files, especially if your
>> users are programmers, perhaps your application program could be a
>> framework, and the config file is the program that the user runs, and
>> that config file program instantiates the framework:
>> https://groups.google.com/forum/#!topic/racket-users/6hn9J-r0Nek
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Any place to get keywords and constants of Racket?

2018-05-05 Thread Shu-Hung You
Here's a list of *some* keywords and regular expressions used by
DrRacket, from line 387 to line 477:
https://github.com/racket/gui/blob/master/gui-lib/framework/private/main.rkt#L387



On Sat, May 5, 2018 at 9:44 AM, piv det  wrote:
> I want to write a Racket mode for ace,
>
> Relate issue: https://github.com/ajaxorg/ace/issues/3659
>
> I was wondering if maybe I could find the full list of keywords of Racket.
>
> The example of scheme language would be:
>
> var e = "case|do|let|loop|if|else|when",
> t = "eq?|eqv?|equal?|and|or|not|null?",
> n = "#t|#f",
> r =
> "cons|car|cdr|cond|lambda|lambda*|syntax-rules|format|set!|quote|eval|append|list|list?|member?|load",
> i = this.createKeywordMapper({
> "keyword.control": e,
> "keyword.operator": t,
> "constant.language": n,
> "support.function": r
> }, "identifier", !0);
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] char-utf-8-length signature is surprising

2018-05-03 Thread Shu-Hung You
Looks like the implementation of char-utf-8-length returns values
fitting the "FSS-UTF (1992) / UTF-8 (1993)" table in
https://en.wikipedia.org/wiki/UTF-8#History. Not sure what's the
standard UTF-8 encoding..

/* racket/src/char.c */
static Scheme_Object *char_utf8_length (int argc, Scheme_Object *argv[])
{
  mzchar wc;
  if (!SCHEME_CHARP(argv[0]))
scheme_wrong_contract("char-utf-8-length", "char?", 0, argc, argv);

  wc = SCHEME_CHAR_VAL(argv[0]);
  if (wc < 0x80) {
return scheme_make_integer(1);
  } else if (wc < 0x800) {
return scheme_make_integer(2);
  } else if (wc < 0x1) {
return scheme_make_integer(3);
  } else if (wc < 0x20) {
return scheme_make_integer(4);
  } else if (wc < 0x400) {
return scheme_make_integer(5);
  } else {
return scheme_make_integer(6);
  }
}


On Thu, May 3, 2018 at 2:12 PM, David Storrs  wrote:
> I noticed this in the docs and it surprised me:
>
> (char-utf-8-length char) → (integer-in 1 6)
>
> UTF-8 characters are 1-4 bytes, so why isn't it (integer-in 1 4)?  I
> feel like this is probably obvious but I'm not coming up with the
> answer.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] Redex trace/ps doesn't produce edges

2018-04-28 Thread Shu-Hung You
Hello everyone,

I try to save the traces generated by Redex to an image. However, the
arrows between the expressions don't show up in the result.

I tried some combinations of #:x-spacing, #:edge-labels? and #:layout
to let the arrows showed up in trace, but the edges remain hidden when
I ran trace/ps. Any clue about this?

code: https://gist.github.com/shhyou/55ab7e060488e8181acc5d50c8eeca4c

Thanks!

Shu-Hung



#lang racket

(require redex/reduction-semantics
 redex/gui)

(define-language L)

(define R
  (reduction-relation
   L
   #:domain integer
   (--> 5 0 "zero!")))

(traces R 5 #:x-spacing 400)
(traces/ps R 5 "trace-ps-image.ps" #:x-spacing 400)

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Re: [racket/racket] bc5556: raco pkg update: add `---unclone` as a kind of ali...

2018-04-25 Thread Shu-Hung You
This is awesome! I never knew that un-cloning can be done by using --lookup.

Shu-Hung

On Wed, Apr 25, 2018 at 12:35 PM, 'John Clements' via Racket Users
 wrote:
> YAY!
>
> I can *never* remember this flag.
>
> Many thanks,
>
> John
>
>> On Apr 25, 2018, at 9:32 AM, Matthew Flatt  wrote:
>>
>>  Branch: refs/heads/master
>>  Home:   https://github.com/racket/racket
>>  Commit: bc55560f8dcef2780c2b64a95c2fc89513e3f447
>>  
>> https://github.com/racket/racket/commit/bc55560f8dcef2780c2b64a95c2fc89513e3f447
>>  Author: Matthew Flatt 
>>  Date:   2018-04-25 (Wed, 25 Apr 2018)
>>
>>  Changed paths:
>>M pkgs/racket-doc/pkg/scribblings/pkg.scrbl
>>M pkgs/racket-test/tests/pkg/tests-clone.rkt
>>M racket/collects/pkg/main.rkt
>>
>>  Log Message:
>>  ---
>>  raco pkg update: add `---unclone` as a kind of alias for `--lookup`
>>
>> It's difficult to remember that the opposite of `--clone` is
>> effectively `--lookup`.
>>
>>
>
>
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] let-syntax example?

2018-04-03 Thread Shu-Hung You
Hi Keven,

Here's an example:

#lang racket
(let-syntax ([a  (lambda (stx)
   (printf "expansion time: stx = ~a\n" stx)
   #'3) ])
a)

However, I would suggest to start at least from syntax objects and
macro transformers in the guide and use define-syntax instead of
let-syntax.
https://docs.racket-lang.org/guide/stx-obj.html
https://docs.racket-lang.org/guide/macro-transformers.html

Best,
Shu-Hung

On Tue, Apr 3, 2018 at 1:31 PM, Kevin Forchione  wrote:
> Hi Guys,
> Does anyone have an analogous example for let-syntax to something as simple 
> as this?
>
> (let ([a 3]) a)
>
> Something like….
>
> (let-syntax ([a 3]) ….)
>
> At which point I’m stumped as to what expression in the body would return 3. 
> There are no examples in the Reference.
>
> Thanks!
> Kevin
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] A very simple #lang

2018-01-25 Thread Shu-Hung You
The explanation of the 5-argument read and 6-argument read-syntax is
here, starting from the 3rd paragraph of this subsection:
https://docs.racket-lang.org/reference/reader.html#%28part._parse-reader%29

The 5 (or 6) arguments version read accepts extra source location
information. However, this version is not exposed in the read
(read-syntax) from racket/base. As far as I know, those
read/read-syntax *might* be accessible when implementing
meta-languages using make-meta-reader. (That gives you the reader of
the underlying language).



On Thu, Jan 25, 2018 at 3:03 PM, Deren Dohoda  wrote:
> Thanks Philip, of course I should have checked for something like this
> directly.
>
> Deren
>
> On Thu, Jan 25, 2018 at 3:51 PM, Philip McGrath 
> wrote:
>>
>> You may just want to use #lang exact-decimal racket (see:
>> http://docs.racket-lang.org/exact-decimal-lang/index.html).
>>
>> I have encountered a similar problem with six arguments to read-syntax
>> before, and I remember there being a good reason that was explained in some
>> obscure corner of the documentation, but I don't remember exactly what the
>> reason was, and I'm not immediately finding it in the documentation, which
>> perhaps suggests that, whatever the reason is, it should be documented more
>> prominently.
>>
>> -Philip
>>
>> On Thu, Jan 25, 2018 at 2:21 PM, Deren Dohoda 
>> wrote:
>>>
>>> Hi everyone,
>>>
>>> I am desperately in need of a #lang exact so that decimals are read as
>>> exact values.
>>>
>>> I thought this would be extremely simple:
>>> ..\exact\lang\reader.rkt
>>>
>>> (module reader racket/base
>>>   (provide (rename-out (exact-read read)
>>>(exact-read-syntax read-syntax)))
>>>   (require (rename-in racket/base (read base:read) (read-syntax
>>> base:read-syntax)))
>>>   (define (exact-read . in)
>>> (parameterize ((read-decimal-as-inexact #f))
>>>   (apply base:read in)))
>>>   (define (exact-read-syntax . in)
>>> (parameterize ((read-decimal-as-inexact #f))
>>>   (apply base:read-syntax in
>>> ;;
>>> It installs alright, though chokes on building docs for some reason, but
>>> then when I attempt to use it:
>>> ..\exact\lang\reader.rkt:13:6: read-syntax: arity mismatch;
>>>  the expected number of arguments does not match the given number
>>>   expected: 0 to 2
>>>   given: 6
>>>   arguments...:
>>>
>>> Why is read-syntax getting six arguments?
>>>
>>> Deren
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "Racket Users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send an
>>> email to racket-users+unsubscr...@googlegroups.com.
>>> For more options, visit https://groups.google.com/d/optout.
>>
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Byte Order Mark: alter display of symbols containing nonprinting characters?

2017-12-27 Thread Shu-Hung You
(Interned) symbols that have the same printed form but are not equal
to each other already exist tho; the symbols produced by
string->unreadable-symbol are not equal? to their counterparts
produced by the reader, but nevertheless have the same printed
representation.

Shu-Hung

On Wed, Dec 27, 2017 at 9:26 PM, 'John Clements' via Racket Users
 wrote:
>
>
>> On Dec 27, 2017, at 19:06, Jay McCarthy  wrote:
>>
>> This seems to be consistent with my Web browser and editor. Are the
>> symbols eq? or equal?
>
> Neither. Am I misunderstanding you? Here’s code:
>
> #lang racket
>
> (define bad-symbol (string->symbol "\uFEFFhello"))
>
> (define regular-symbol 'hello)
>
> bad-symbol
> regular-symbol
> (equal? bad-symbol regular-symbol)
> (eq? bad-symbol regular-symbol)
>
> this evaluates in DrR to:
>
> Welcome to DrRacket, version 6.11.0.5--2017-12-20(-/f) [3m].
> Language: racket, with debugging; memory limit: 4096 MB.
> 'hello
> 'hello
> #f
> #f
>>
>
> If you copy and paste these from the interactions into the definitions 
> window, you can even get this:
>
> #lang racket
>
> (equal? 'hello 'hello)
> (eq? 'hello ‘hello)
>
> evaluates to:
>
> Welcome to DrRacket, version 6.11.0.5--2017-12-20(-/f) [3m].
> Language: racket, with debugging; memory limit: 4096 MB.
> #f
> #f
>>
>
> Did you misunderstand me, or did I misunderstand you?
>
> John
>
>
>
>
>
>>
>
>> On Wed, Dec 27, 2017 at 3:54 PM, 'John Clements' via Racket Users
>>  wrote:
>>> I was working with files containing a Byte Order Mark today, and in the 
>>> process of writing a test case, I discovered that
>>>
>>> (string->symbol “\uFEFF”)
>>>
>>> produces a symbol whose printed representation is
>>>
>>> ‘hello
>>>
>>> … which seems unfortunate; I guess I would have expected something like
>>>
>>> ‘|\uFEFFhello|
>>>
>>> (… although I see now that this kind of escaping is not currently enabled 
>>> inside vertical bars).
>>>
>>> This leads to situations where two symbols with the same printed 
>>> representation may not be equal?, which seems unfortunate.
>>>
>>> Am I overlooking a good reason why this is the desired behavior?
>>>
>>> John
>>>
>>>
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups 
>>> "Racket Users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send an 
>>> email to racket-users+unsubscr...@googlegroups.com.
>>> For more options, visit https://groups.google.com/d/optout.
>>
>>
>>
>> --
>> -=[ Jay McCarthy   http://jeapostrophe.github.io]=-
>> -=[ Associate ProfessorPLT @ CS @ UMass Lowell ]=-
>> -=[ Moses 1:33: And worlds without number have I created; ]=-
>>
>> --
>> You received this message because you are subscribed to the Google Groups 
>> "Racket Users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to racket-users+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>
>
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] structs vs classes

2017-12-07 Thread Shu-Hung You
I'm not sure whether the following is a good idea, but it more or less
works. The impersonate-struct function allows one to redirect the some
or all of accessor and mutator functions on *individual struct
instances*. If the actual constructor is hidden from the user and only
a ``smart'' constructor is exported, then we can put impersonators on
all struct instances.

#lang racket

(provide
 smart-db-chunk-approach-1
 smart-db-chunk-approach-2

 (except-out
  (struct-out db-chunk)
  make-db-chunk))

(struct db-chunk (scratchdir-path chunkdir-path) #:mutable
  #:constructor-name make-db-chunk
  #:transparent ;; for impersonators
  ;; and perhaps guards
  )


;; approach 1: save path-string? in struct fields and redirect accessors
(define (smart-db-chunk-approach-1 . args)
  (impersonate-struct
   (apply make-db-chunk args)

   db-chunk-scratchdir-path
   (λ (chnk v) (if (path? v) (path->string v) v))
   db-chunk-chunkdir-path
   (λ (chnk v) (if (path? v) (path->string v) v

(define s1 (smart-db-chunk-approach-1 (string->path "/usr") "/var"))
(string? (db-chunk-scratchdir-path s1))



;; approach 2: redirect mutators and only save string? in struct fields
(define (smart-db-chunk-approach-2 . args)
  (impersonate-struct
   (apply make-db-chunk args)

   set-db-chunk-scratchdir-path!
   (λ (chnk v) (if (path? v) (path->string v) v))
   set-db-chunk-chunkdir-path!
   (λ (chnk v) (if (path? v) (path->string v) v

(define s2 (smart-db-chunk-approach-2 "/usr" "/var"))
(set-db-chunk-chunkdir-path! s2 (string->path "/bin"))
(string? (db-chunk-scratchdir-path s2))

--Shu-Hung

On Thu, Dec 7, 2017 at 10:10 AM, David Storrs  wrote:
> Wow.  Thank you, Matthias.  That's impressive.
>
> On Thu, Dec 7, 2017 at 10:46 AM, Matthias Felleisen
>  wrote:
>>
>> On Dec 6, 2017, at 10:45 PM, David Storrs  wrote:
>>
>> I have a struct that looks like this (simplified for concision):
>>
>> (struct db-chunk (scratchdir-path chunkdir-path) #:mutable)
>>
>> I'd like to ensure that:
>>
>> 1) At least one of the fields must be set at creation
>> 2) Both fields will accept only a path-string? value
>> 3) Both fields will return string? when accessed, as that makes it
>> easier to insert into the DB when the time comes.
>>
>> I can put a #:guard parameter on db-chunk that will check #1 and #2
>> and (if necessary) transform the input into a string in order to
>> satisfy #3, but that only works at initialization.  From there I would
>> need to redefine the mutator:
>>
>> (struct db-chunk (scratchdir-path chunkdir-path) #:mutable)
>>
>> (let ([old-mut set-db-chunk-scratchdir-path!])
>>  (set! set-db-chunk-scratchdir-path!
>>  (lambda (chnk val)
>>(old-mut chnk (if (path? val) (path->string val) val))
>>
>> Alternatively, I could define my struct and then make a bunch of
>> custom manipulation functions, but then (a) I've got these unguarded
>> functions floating around and (b) I've given up a major advantage of
>> structs, which is their concision.
>>
>>
>> Consider the introduction of a syntax transformer that refines struct
>> according to your needs. The sketch below is a bit brittle but if you
>> need to strengthen it, I am sure our virtual macrologists can help.
>>
>> — Matthias
>>
>>
>>
>>
>> #lang racket
>>
>> ;; ---
>> ;; in some module/file:
>>
>> #;
>> (provide
>>  ;; SYNTAX(struct/ccc Id [Id ...] MINUS Id ...)
>>  ;; SEMANTICS (struct/ccc a [b ...] MINUS c ...) is like
>>  ;;  (struct a [b ...]) but hides the struct-defined functions
>>  ;;  c ...
>>  struct/ccc)
>>
>> (define-syntax (struct/ccc stx)
>>   (syntax-case stx (MINUS PLUS)
>> [(struct/ccc s [a ...] (MINUS x ...) (PLUS [f ex] ...))
>>  ;; ==>
>>  (let ((my-require (datum->syntax stx '(require 'server
>>#`(begin
>>(module server #,(datum->syntax stx 'racket)
>>  (provide
>>   (except-out (struct-out s) x ...))
>>  (struct s [a ...])
>>  (set! f ex) ...)
>>#,my-require))]))
>>
>> ;; ---
>> ;; require the module here
>>
>> (struct/ccc s [a b c]
>> (MINUS s-a)
>> (PLUS [s-b (let ((old s-b)) (λ (x) (define b (old x)) (* 2
>> b)))]))
>> (define s0 (s 1 2 3))
>> (s-b s0)
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit 

Re: [racket-users] namespace-variable-value thinks functions are bound to syntax

2017-10-30 Thread Shu-Hung You
Yes, because keyword functions expand to macro definitions that try to
optimize keyword applications.

namespace-require and namespace-variable-value are relatively
low-level operations on modules and namespaces. Using dynamic-require
could be a bit easier:

#lang racket

(module p racket
  (provide (all-defined-out))

  (define (foo0 a b)
(+ a b))
  (define (foo1 a b [c 3])
(+ a b c))
  (define (foo2 a b [c 3] #:kw1 kw1)
(+ a b c))
  (define (foo3 a b [c 3] #:kw1 kw1 #:kw2 [kw2 1])
(+ a b c))
  )

(require syntax/location)

(define ns (make-base-empty-namespace))

(parameterize ([current-namespace ns])
  (dynamic-require (quote-module-path p) 'foo0))
;=> #

(parameterize ([current-namespace ns])
  (dynamic-require (quote-module-path p) 'foo1))
;=> #

(parameterize ([current-namespace ns])
  (dynamic-require (quote-module-path p) 'foo2))
;=> #

(parameterize ([current-namespace ns])
  (dynamic-require (quote-module-path p) 'foo3))
;=> #

Please note that dynamic-require handles macro exports specially, as
stated in the doc:

https://docs.racket-lang.org/reference/Module_Names_and_Loading.html#%28def._%28%28quote._~23~25kernel%29._dynamic-require%29%29
> If the module exports _provided_ as syntax,
> then a use of the binding is expanded and
> evaluated in a fresh namespace to which
> the module is attached, which means that
> the module is visited in the fresh namespace.
> The expanded syntax must return a single value.

Best,
Shu-Hung

On Sun, Oct 29, 2017 at 7:40 PM, Junsong Li  wrote:
> Hello list,
>
> In the following program, racket thinks foo2, and foo3 are bound to
> syntax. Is this expected behavior?
>
> -- File: go.rkt
>
> #lang racket
>
> (module p racket
>   (provide (all-defined-out))
>
>   (define (foo0 a b)
> (+ a b))
>   (define (foo1 a b [c 3])
> (+ a b c))
>   (define (foo2 a b [c 3] #:kw1 kw1)
> (+ a b c))
>   (define (foo3 a b [c 3] #:kw1 kw1 #:kw2 [kw2 1])
> (+ a b c))
>   )
>
> (require syntax/location)
>
> (define ns (make-base-empty-namespace))
> (parameterize ([current-namespace ns])
>   (namespace-require (quote-module-path p)))
>
> (namespace-variable-value 'foo0 #t #f ns) ; OK
> (namespace-variable-value 'foo1 #t #f ns) ; OK
> (namespace-variable-value 'foo2 #t #f ns) ; namespace-variable-value:
> bound to syntax in: foo2
> (namespace-variable-value 'foo3 #t #f ns) ; namespace-variable-value:
> bound to syntax in: foo3
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] DrR compilation progress bar

2017-10-28 Thread Shu-Hung You
I think printing which file is currently being loaded can also help,
like the logs given by enter! #:verbose. These logs can also be
printed to the interaction window and be erased after the loading
process is finished. This can let the user know that something is
actually running.

--Shu-Hung

On Sat, Oct 28, 2017 at 3:42 PM, Ben Greenman
 wrote:
> I like the output `raco make -v ` gives on the command-line.
>
> How about piping that into the interactions window?
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Confusing typed/racket error message

2017-10-03 Thread Shu-Hung You
Hi Taahir,

The keyword is #:replacement? instead of #:replacement (note the
question mark). I don't know enough Typed Racket to understand that
error message tho, sorry.

Cheers,
Shu-Hung

On Tue, Oct 3, 2017 at 1:40 AM, Taahir Ahmed  wrote:
> Hi,
>
> I have been implementing some toy problems in typed/racket.  However,
> I have hit a wall while trying to invoke `(random-sample)`.  This
> example program:
>
> 
> #lang typed/racket
>
> (require typed/racket/random)
>
> (define (example (limit : Integer)
>  (count : Integer))
>   : (Listof Integer)
>   (let* ((random-sample-inst (inst random-sample Integer)))
> (random-sample-inst (in-range -10 limit)
> count
> #:replacement #f)))
>
> (example 10 5)
> 
>
> gives the error message:
>
> 
> ; /home/ahmedtd/project/reinforcement-learning/type-reproducer.rkt:9:4:
> Type Checker: No function domains matched in function application:
> ; Types: (Sequenceof Integer) Integer Pseudo-Random-Generator #f * ->
> (Listof Integer)
> ;(Sequenceof Integer) Integer #f * -> (Listof Integer)
> ; Arguments: (Sequenceof Integer) Integer #f *
> ; Expected result: (Listof Integer)
> ;
> ;   in: (random-sample-inst (in-range -10 limit) count #:replacement #f)
> 
>
> Maybe I'm missing something obvious, but it seems like the types of
> the supplied arguments are an exact match for the types of the second
> candidate domain printed in the error message.
>
> Any ideas on how to invoke this function from typed/racket?
>
> Thanks,
>
> Taahir Ahmed
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] ~literal vs ~datum

2017-09-11 Thread Shu-Hung You
I think the case here is a little subtle. The syntax object #'(define
x y) has actually gone through expansion, but Racket's new expansion
model will prune this syntax object's local scopes [1]. One could use
#:local [2] in this case to see the difference:

> (syntax-parse (let ([define 'something-else]) (quote-syntax (define x y)))
[((~literal define) var:id e:expr) 'yes]
[_ 'no])
'yes

> (syntax-parse (let ([define 'something-else]) (quote-syntax (define x y) 
> #:local))
[((~literal define) var:id e:expr) 'yes]
[_ 'no])
'no

The original doc predates the new expander and the result was probably
'no in the old expansion model.

Best,
Shu-Hung

1. 
http://www.cs.utah.edu/plt/scope-sets/general-macros.html#%28part._.Local_.Bindings_and_.Syntax_.Quoting%29

2. https://docs.racket-lang.org/reference/Syntax_Quoting__quote-syntax.html


On Thu, Aug 3, 2017 at 1:53 PM, Jordan Johnson  wrote:
> On Aug 1, 2017, at 11:34, Jens Axel Søgaard  wrote:
>
> The binding information is attached a syntax object during expansion.
> In your example the #'(define x y) haven't gone through expansion,
> so you do not get what your expected result.
>
> However we can change your macro a little...
>
>
> Ah, that clarifies everything. Thanks!
>
> So, the example I quoted is actually from the docs on ~datum, and it seems
> pretty clear that it’s trying unsuccessfully to elicit different behaviors
> that show the difference between ~literal and ~datum. Based on the code
> you’ve provided, I think this would be a better illustration:
>
> (define-syntax (is-define? stx)
>   (syntax-parse stx
> [(_is-define? id)
>  (syntax-parse #'id
>[(~literal define) #''yes]
>[(~datum   define) #''not-really]
>[_ #''not-even-close])]))
>
> (is-define? define) ;; 'yes
>
> (let ([define 42])
>   (is-define? define))  ;; 'not-really
>
> (is-define? something-else) ;; 'not-even-close
>
>
> I’ve submitted that as a PR on the doc file linked above. I hope you don’t
> mind my using your example in that way. It was very helpful.
>
> Regards,
> Jordan
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] How to load net/jwt

2017-09-10 Thread Shu-Hung You
This command should install the net-jwt library for you:

raco pkg install net-jwt

--Shu-Hung

On Mon, Sep 11, 2017 at 9:15 AM, Chongkai Zhu  wrote:
> Hi all,
>
> https://docs.racket-lang.org/jwt/index.html
>
> It seems I just need to (require net/jwt) in racket 6.10 and everything
> should work. But:
>
> Welcome to DrRacket, version 6.10 [3m].
> Language: racket, with debugging; memory limit: 128 MB.
> . unsaved-editor:2:9: cannot open module file
>   module path: net/jwt
>   path: /usr/racket/collects/net/jwt.rkt
>   system error: No such file or directory; errno=2 in: net/jwt
>   no packages suggestions are available .
>
>
> So how should I install net/jwt? Thanks.
>
> Best,
> Chongkai
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Suppress print lines from required modules

2017-08-27 Thread Shu-Hung You
Parameterizing current-output-port to (open-output-string) redirects
the output to a string. Something along the line of (open-output-file
"/dev/null") sounds a bit better but I'm not sure how to create a
discard-everything output port.

(define ns (make-base-namespace))

(parameterize ([current-namespace ns])
  (eval '(module a racket
   (displayln "a line from module a")
   (provide x)
   (define x 5

(printf "value of x is ~a\n"
(parameterize ([current-namespace ns]
   [current-output-port (open-output-string)])
  (dynamic-require ''a 'x)))

Shu-Hung

On Mon, Aug 28, 2017 at 10:22 AM, Sam Waxman  wrote:
> Let's say I have a module that looks like
>
> (module a racket
>(provide result)
>(print "Annoying print line!")
>(define result 2))
>
> and I'd like the value of result in another module, so in another module, I 
> write
>
> (require a)
>
> or
>
> (dynamic-require ''a 'result)
>
> In both cases, I get the value of result, but by requiring the module, the 
> print line "Annoying print line!" will show up on my screen and be part of 
> the output of the program.
>
> Is there a way to get the value of result from module a without triggering 
> the print, or hiding it in some way? I've played around with print-handlers, 
> but it seems anything I do outside of module a won't affect the printer 
> inside module a.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Re: Readers and Namespaces

2017-08-18 Thread Shu-Hung You
If you are implementing a new language, this can be done by delegating
the "=-to-let" work to the macro-expander and let the reader simply
parenthesizing the input into s-expression form. In this approach, we
don't need to worry about being hygienic in the reader since the
actual work is done by the macro expander.

For example, we can make the reader turn the following input

; a-test.rkt
#lang my-let-lang
x = 5;
a = 8;
my-let = 10;
= = a + a;
u = x + my-let + = + = + = + = + =;
printf("u = ~a\n", u);

into some parenthesized form

(module a-test my-let-lang
(= x 5) (= a 8) (= my-let 10) (= = (+ a a))
(= u (+ x my-let = = = = =))
(printf "u = ~a\n" u))

and implement a module-begin macro that turns the parenthesized body
into my-let.

(provide
 (rename-out [new-module-begin #%module-begin]))
(require
 (rename-in racket [#%module-begin racket-module-begin]))

(define-syntax (new-module-begin stx)
  (syntax-parse stx
; parse the s-exp-ized "=" syntax here
[(_ (= x:id e:expr) ... body)
 #'(racket-module-begin
(make-nested-my-let ((x e) ...) body))]))

--Shu-Hung

On Fri, Aug 18, 2017 at 9:21 AM, gfb  wrote:
> Assuming the setup where you make a module syntax object and call 
> strip-context on it, you can add a scope to all the user's identifiers after 
> that so they're not considered “above” any of the language's identifiers. 
> Make a function to do the marking:
>
> (define marker (make-syntax-introducer #true))
>
> Then walk the syntax object tree and replace each user identifier ‘id’ with 
> (marker id 'add). Depending on your parsing setup, you could have a specific 
> non-terminal for places a user identifier occurs and have a very generic 
> syntax tree walker that looks for the non-terminal and adds the mark to the 
> identifier.
>
> If you make a second marker for all other identifiers you encounter, then 
> none of the user's identifiers will be “under” the language's bindings, and 
> error messages will be better if the user accidentally uses (without binding) 
> one of the language's names.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Re: Racket from Homebrew has trouble when upgrading

2017-08-07 Thread Shu-Hung You
>From this thread, it seems that the original formula it not actively
maintained. But the thread also mentions `cask`, probably worth a try.
https://groups.google.com/forum/#!msg/racket-dev/Zyl9m8UWvp0/GVDcHVkWAwAJ

Best,
Shu-Hung

On Mon, Aug 7, 2017 at 6:23 PM,   wrote:
> It seems I got it working now. I deleted `(find-system-path 'config-dir)` and 
> `(find-system-path 'addon-dir)`. My bet is that the former was the culprit. 
> We'll see about that when 6.11 is released.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Correctly executing a source file from embedded Racket

2017-07-26 Thread Shu-Hung You
Hi Thomas,

I tried following Matthew's suggestions to attach my-lang and use
dynamic-require. Turns out that works pretty well! And then there's
even no need to setup collection path since everything loads from
compiled byte-code.
https://gist.github.com/shhyou/aa2adaf7e1b7d548783cee352c3230a9

The code is basically calling (dynamic-require `(file ,argv-1) #f) to
run the external script. At line 35, the code builds (list 'file
argv-1) and at line 41 the code dynamic-requires the script.

/* custom_dsl.cpp

$ raco ctool --cgc --c-mods base.c ++lib racket/base ++lib
racket/base/lang/reader ++lib racket/runtime-config ++lib my-lang
++lib my-lang/lang/reader

$ g++ -framework Foundation -I/racket/include
-L/racket/src/build/racket
-L/racket/src/build/rktio custom_dsl.cpp -o
custom_dsl -lracket -lmzgc -lrktio -liconv

$ ./custom_dsl ./a-module.rkt

 */
#include 
#include 

#include "base.c"

static int run(Scheme_Env *e, int argc, char *argv[])
{
  Scheme_Object *curout;
  int i;
  Scheme_Thread *th;
  mz_jmp_buf * volatile save, fresh;

  /* Declare embedded modules in "base.c": */
  declare_modules(e);
  scheme_namespace_require(scheme_intern_symbol("my-lang"));

  curout = scheme_get_param(scheme_current_config(),
  MZCONFIG_OUTPUT_PORT);

  th = scheme_get_current_thread();

  save = th->error_buf;
  th->error_buf = 
  if (scheme_setjmp(*th->error_buf)) {
th->error_buf = save;
return -1; /* There was an error */
  } else {
std::cout << "Trying to load file from \"" << argv[1] << "\"\n";
Scheme_Object *custom_dsl_path[2];
custom_dsl_path[0] = scheme_make_pair(
   scheme_intern_symbol("file"),
   scheme_make_pair(
 scheme_make_utf8_string(argv[1]),
 scheme_make_null()));
custom_dsl_path[1] = scheme_make_false();
Scheme_Object *custom_dsl = scheme_dynamic_require(2, custom_dsl_path);
th->error_buf = save;
  }
  return 0;
}


int main(int argc, char **argv) {
  std::cout << "In cpp main\n";
  return scheme_main_setup(1, run, argc, argv);
}



;; a-module
#lang my-lang
some 'DSL that turns everything into "quotes"

Cheers,
Shu-Hung

On Wed, Jul 26, 2017 at 10:09 AM, Matthew Flatt  wrote:
> At Wed, 26 Jul 2017 07:54:32 -0700 (PDT), Thomas Dickerson wrote:
>> One more thing: in terms of repeatedly executing scripts, does it make sense
>> to set up and tear down the interpreter every time? Or just swap in a fresh
>> namespace?
>
> Between those two options, a fresh namespace is almost certainly
> better.
>
> Depending on how much you need to reset, you might be even better off
> with `dynamic-rerequire` from `racket/rerequire`.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Correctly executing a source file from embedded Racket

2017-07-25 Thread Shu-Hung You
Hi Thomas,

I think the program is more of Racket programming setup rather than
embedding Racket. When start a Racket program on our own, we have to
setup the environment correctly.

Here is my test program that can load an external program and the
accompanying commands (also attached at the end). It has been tested
the program on Mac OS X 10.11 with Racket head.
https://gist.github.com/shhyou/e424424236d1bc685fa002192221c29b

The program can also work for user-defined languages by adding ++lib
some-lang ++lib some-lang/lang/reader as usual.

Here are some thoughts:



* That error message looks like trying to run a program from an empty
namespace. For example,

$ cat a-module.rkt
#lang racket/base

123

$ cat run-from-empty-ns.rkt
#lang racket

(define host-ns (current-namespace))
(define ns (make-empty-namespace))

(parameterize ([current-namespace ns])
  (namespace-attach-module host-ns ''#%builtin)
  (load "a-module.rkt"))

$ racket run-from-empty-ns.rkt
a-module.rkt:2:0: #%top-interaction: unbound identifier;
 also, no #%app syntax transformer is bound
  at: #%top-interaction
  in: 

As we can see, `scheme_namespace_require(scheme_intern_symbol("racket/base"));`
is actually missing from your setup program. This line requires racket
base and the usual #%app bindings. It's probably needed even if you're
loading your own DSL -- I suspect at some point racket/base will
install the right `load` function to make things work, and that this
will also affect loading custom #langs.



* Dependencies for main.rkt and lang/reader.rkt: I don't think there's
a conflict. The dependencies seem to refer to `require`s, like
racket/base -> racket/list, racket/...



* load: instead of using load, I would probably try to implement a
function in Racket that use `dynamic-require` to load other DSL
scripts. Then in the C part, we can `dynamic-require` that function to
load argv[1]. Of course, remember to add that module in raco ctool. An
example is given in load-file.rkt and call_racket_from_load.cpp in the
link.

I am not familiar with this; there could be a better way to
dynamically load a file.



Cheers,
Shu-Hung


# Commands:
$ raco ctool --c-mods base.c ++lib racket/base ++lib
racket/base/lang/reader ++lib racket/runtime-config

$ g++ -framework Foundation -I/racket/include
-L/racket/src/build/racket
-L/racket/src/build/rktio call_racket.cpp -o
call_racket -lracket -lmzgc -lrktio -liconv
ld: warning: could not create compact unwind for _ffi_call_unix64:
does not use RBP or RSP based frame

$ ./call_racket "/racket/collects"
In cpp main
Trying to load file from "a-module.rkt"
#

In cpp: Instantiating the loaded module, `a-module`:
In Racket: module instantiated: ("this is in a function with" arg
"being the first argument")
12354

In cpp: get the value of `a-value`:
a-value is 12354



;; a-module.rkt
#lang racket/base

(provide (all-defined-out))

(define (a-binding-to-a-function x)
  (list "this is in a function with" x "being the first argument"))

(printf "In Racket: module instantiated: ~s\n" (a-binding-to-a-function 'arg))

(define a-value 12354)

;; By default, this should print 12354
a-value


/* call_racket.cpp */
/*
raco ctool --c-mods base.c ++lib racket/base ++lib
racket/base/lang/reader ++lib racket/runtime-config
g++ -framework Foundation -I/racket/include
-L/racket/src/build/racket
-L/racket/src/build/rktio call_racket.cpp -o
call_racket -lracket -lmzgc -lrktio -liconv
./call_racket "/racket/collects"
 */
#include 
#include 

#include "base.c"

static int run(Scheme_Env *e, int argc, char *argv[])
{
  Scheme_Object *curout;
  int i;
  Scheme_Thread *th;
  mz_jmp_buf * volatile save, fresh;

  /* Declare embedded modules in "base.c": */
  declare_modules(e);

  scheme_namespace_require(scheme_intern_symbol("racket/base"));

  curout = scheme_get_param(scheme_current_config(),
  MZCONFIG_OUTPUT_PORT);

  th = scheme_get_current_thread();

  Scheme_Object *path = scheme_make_path(argv[1]);
  {
scheme_set_collects_path(path);

/*
// init collection paths with `((dynamic-require 'racket/base 'list) argv-1)
Scheme_Object *rkt_list_sym[2], *args[1];
rkt_list_sym[0] = scheme_intern_symbol("racket/base");
rkt_list_sym[1] = scheme_intern_symbol("list");
args[0] = path;
Scheme_Object *paths = scheme_apply(scheme_dynamic_require(2,
rkt_list_sym), 1, args);
scheme_init_collection_paths(e, paths);
*/
scheme_init_collection_paths(e, scheme_null);
  }

  save = th->error_buf;
  th->error_buf = 
  if (scheme_setjmp(*th->error_buf)) {
th->error_buf = save;
return -1; /* There was an error */
  } else {
std::cout << "Trying to load file from \"a-module.rkt\"\n";
Scheme_Object *load_result = scheme_load("a-module.rkt");
scheme_display(load_result, curout);
scheme_display(scheme_make_char('\n'), curout);

// Instantiate the loaded module
std::cout << "\nIn cpp: Instantiating the loaded module, `a-module`:\n";

Re: [racket-users] Can raco distribute produce a single executable?

2017-02-20 Thread Shu-Hung You
Sorry, I saw that you're already using raco exe and raco distribute.
So is the problem related to some DLL issue on Windows?

Best,
Shu-Hung

On Mon, Feb 20, 2017 at 1:19 PM, Shu-Hung You
<shu-hung@eecs.northwestern.edu> wrote:
> https://docs.racket-lang.org/raco/exe.html
> Is raco exe in this page what you want? Just type
>
>> raco exe q.rkt
>
> And this command will produce a single executable. Now we can now run
>
>> ./q
> q: expects 1  on the command line, given 0 arguments
>
> Best,
> Shu-Hung
>
> On Mon, Feb 20, 2017 at 1:12 PM, lu <luke...@gmail.com> wrote:
>> Hi all, I have this little toy project[1] to help me learn the language. I 
>> would like to produce a single portable executable that can be executed 
>> without reliance on racket installation. `raco distribute` does produce a 
>> "package" folder. But for small utility tool like this, I would prefer a 
>> simple standalone executable file rather than a folder, so I can just drop 
>> it into a directory on `PATH` on the target machine and run it.
>>
>> For the start I'm looking at solving this problem for Windows specifically, 
>> but am also interested in a solution on other systems.
>>
>> Thanks!
>>
>>
>> [1]: https://github.com/kflu/q
>>
>> --
>> You received this message because you are subscribed to the Google Groups 
>> "Racket Users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to racket-users+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Can raco distribute produce a single executable?

2017-02-20 Thread Shu-Hung You
https://docs.racket-lang.org/raco/exe.html
Is raco exe in this page what you want? Just type

> raco exe q.rkt

And this command will produce a single executable. Now we can now run

> ./q
q: expects 1  on the command line, given 0 arguments

Best,
Shu-Hung

On Mon, Feb 20, 2017 at 1:12 PM, lu  wrote:
> Hi all, I have this little toy project[1] to help me learn the language. I 
> would like to produce a single portable executable that can be executed 
> without reliance on racket installation. `raco distribute` does produce a 
> "package" folder. But for small utility tool like this, I would prefer a 
> simple standalone executable file rather than a folder, so I can just drop it 
> into a directory on `PATH` on the target machine and run it.
>
> For the start I'm looking at solving this problem for Windows specifically, 
> but am also interested in a solution on other systems.
>
> Thanks!
>
>
> [1]: https://github.com/kflu/q
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Why is this exception giving me an arity error?

2017-02-17 Thread Shu-Hung You
This works completely fine on a fresh racket REPL:

> (exn:fail:bmtc:unknown-user "message" (current-continuation-marks) "bob")
(exn:fail:bmtc:unknown-user "message" # "bob")

I guess there might be some inconsistency in REPL states. Starting a
fresh racket should work, or maybe use (enter! "./module.rkt")?

Best,
Shu-Hung


On Fri, Feb 17, 2017 at 12:17 PM, David Storrs  wrote:
> I have the following file:
>
>
> #lang racket
>
> (provide (all-defined-out))
>
> (struct exn:fail:bmtc exn:fail ()
> #:extra-constructor-name make-exn:fail:bmtc
> #:transparent)
>
> ;; I expect this to take all the arguments from exn (its ultimate
> superclass), plus a new argument which comes last.
> (struct exn:fail:bmtc:unknown-user exn:fail:bmtc (username)
> #:extra-constructor-name make-exn:fail:bmtc:unknown-user
> #:transparent)
>
>
> At the command line:
>
> $ racket
> -> (require "network/exceptions")
>
> -> exn:fail:bmtc:unknown-user
> #
>
> -> (exn:fail:bmtc:unknown-user "message" (current-continuation-marks) "bob")
> ; exn:fail:bmtc:unknown-user: arity mismatch;
> ;  the expected number of arguments does not match the given number
> ;   expected: 2
> ;   given: 3
> ; [,bt for context]
>
> -> (exn:fail:bmtc:unknown-user "msg" (current-continuation-marks))
> (exn:fail:bmtc:unknown-user "msg" #)
>
>
> Given the declaration of exn:fail:bmtc:unknown-user I was expecting it to
> take a third argument.  What am I missing?
>
>
> Note that I'm using Emacs and the command line, not DrRacket.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users]

2016-12-19 Thread Shu-Hung You
The documentation of impersonate-procedure states that if it is
invoked with wrapper-proc equals #f and that there are no props, then
the result is proc "unimpersonated".

However, neither the impersonator wrapper-function nor the
impersonator properties are removed in the following program, and the
resulting function is still an impersonator?. What does
"unimpersonated" mean then?

(define-values (imp-prop:a imp-prop:a? imp-prop:a-get)
  (make-impersonator-property 'a))

(define (add8 n) (+ n 8))

(define impersonated
  (impersonate-procedure add8 (lambda (x) (+ x 1)) imp-prop:a "a value"))

(define unimpersonated (impersonate-procedure impersonated #f))

(unimpersonated 10)
;=> 19

(impersonator? unimpersonated)
;=> #t

(imp-prop:a? unimpersonated)
;=> #t

(imp-prop:a-get unimpersonated)
;=> "a value"

Best,
Shu-Hung

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Where is "PLT Games.exe" source code?

2016-11-23 Thread Shu-Hung You
Hi Ken, do you mean this? https://github.com/racket/games
--Shu-Hung

On Wed, Nov 23, 2016 at 2:02 PM, Ken Biondi  wrote:
> Where is the source code for "PLT Games.exe"?  I unsuccessfully searched 
> github for it.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] How to 'apply' a function with optional parameters?

2016-10-29 Thread Shu-Hung You
Hi Meino,

Could you give an example of lst or line? Unlike string-append, most of the time
string-join doesn't really require an 'apply'. As we can see:

> (string-append "a" "b" "c")
"abc"
> (string-join '("a" "b" "c") ":")
"a:b:c"

While string-append takes all its arguments and concatenates them into a string,
string-join simply joins all the strings in its first argument (which
should be a list of strings).
So suppose we have 'line' to be a list of string, then string-append
and string-join can
be used as follows:

> (define line '("x" "y" "z"))
> (apply string-append line)
"xyz"
> (string-join line " ")
"x y z"

If string-join is really to be used with apply, then we need to first
construct its arguments
into a list. For instance, the first of example of string-join is turned into:

> (string-join '("a" "b" "c") ":")
"a:b:c"
> (apply string-join '(("a" "b" "c") ":"))
"a:b:c"

Given 'line' to be a list of strings, we need to construct the
separator as the second item in
the argument list of string-join:

> (define line '("x" "y" "z"))
> (apply string-join (list line " "))
"x y z"

Best,
Shu-Hung

On Sat, Oct 29, 2016 at 10:31 AM,   wrote:
>
> Hi Stephen,
>
> thanks for yoru reply ! ::)
>
> At the certain point of the program I get
> a list as parameter 'lst', which contains
> the sublists of strings. I wrote this
> function:
>
>
> (define (to-txt lst)
>   (if (empty? lst)
> lst
> (let ((line (car lst)))
>   (begin
> (displayln (apply string-join line " " )) ;;; WRONG SYNTAX HERE
> (to-txt (cdr lst))
>
> Since I get the sublists as parameters I need an 'apply' to 'inject'
> (sorry...I am no native speaker...) 'string-join' into the list.
>
> But string-join has additional parameters, and I dont know how to
> combine those with 'apply'?
>
> PS: The resulting strings will later be processed further... the
> 'displayln' is just a placeholder...
>
> Cheers,
> Meino
>
>
> Stephen Chang  [16-10-29 17:16]:
>> string-join already expects a list of strings, so are you sure you want 
>> apply?
>> Can you give a more specific example?
>>
>> Perhaps map or some other iteration is what you want?
>>
>> (for ([strs '(("a" "b") ("c" "D" "E"))])
>>   (displayln (string-join strs " ")))
>>
>> =>
>> a b
>> c D E
>>
>> On Sat, Oct 29, 2016 at 10:27 AM,   wrote:
>> > Hi,
>> >
>> > ...still improving my shortwave-broadcaster-dumper... :)
>> >
>> > I have a list with sublists of strings, which I want to concatenate.
>> > Each sublist shall form one line of output.
>> > I tried 'string-append', but this gives me something like this
>> > (excerpt):
>> > "189RikisutvarpidRas1+2-24001234567Icelandic"
>> > ...the separating #\space is missing.
>> >
>> > The according code looks like this (excerpt)
>> >
>> > (apply string-append sublist)
>> >
>> > then I found 'string-join' which has extra-parameters
>> > to define separator of all kinds.
>> >
>> > ...but...how can I express the 'apply'-instruction...with the
>> > addional parameters???
>> >
>> > This looks something inbetween funny and weird:
>> >
>> > (apply string-join sublist " ")
>> >
>> > and racket mumbles:
>> > apply: contract violation
>> >   expected: list?
>> >   given: " "
>> >   argument position: 3rd
>> >   other arguments...:
>> >#
>> >
>> >
>> > ?
>> >
>> > Cheers
>> > Meino
>> >
>> >
>> >
>> >
>> >
>> > --
>> > You received this message because you are subscribed to the Google Groups 
>> > "Racket Users" group.
>> > To unsubscribe from this group and stop receiving emails from it, send an 
>> > email to racket-users+unsubscr...@googlegroups.com.
>> > For more options, visit https://groups.google.com/d/optout.
>>
>> --
>> You received this message because you are subscribed to the Google Groups 
>> "Racket Users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to racket-users+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] Re: Compare parts of string or compare with wildcard.

2016-10-28 Thread Shu-Hung You
Hi Ken,
string-prefix? does exactly what you want.

> (define a "this") (define b "that") (define c "thisandthat")
> (string-prefix? c a)
#t
> (string-prefix? c b)
#f

https://docs.racket-lang.org/reference/strings.html#%28def._%28%28lib._racket%2Fstring..rkt%29._string-prefix~3f%29%29

Best,
Shu-Hung

On Friday, October 28, 2016 at 11:19:26 AM UTC-5, Ken MacKenzie wrote:
> I have two things I am trying to compare, both strings.
> 
> What I want to know is if string a is the beginning of string b.
> 
> Example (pseudo code)
> 
> string a = this
> string b = that
> string c = thisandthat
> 
> a... == c #t
> b... == c #f
> 
> Hope I am making sense here.  I couldn't figure out a way so at present my 
> program does this
> 
> (define alen (length astr))
> (define bpart (substring bstr 0 alen))
> (cond
>   [(string=? astr bpart) #t]
>   [else #f])
> 
> That is working, but it seems like there should be a simpler solution to this.
> 
> Ken

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.