Re: [racket-users] Re: inflate/deflate

2021-12-10 Thread reilithion


On Friday, January 13, 2017 at 5:32:51 AM UTC-8 Tony Garnock-Jones wrote:

> On 01/12/2017 11:32 PM, Lehi Toskin wrote: 
> > P.S. I didn't see an implementation of ADLER32 anywhere, so I had to 
> write my own, which took a little longer than expected, but oh well. 
>
> Oh, cool. That'd probably be a useful thing for Racket's 
> net/git-checkout module, which has a piece of code in `zlib-inflate` 
> that reads: 
>
> ... 
> (inflate i o) 
> ;; Verify checksum? 
> (read-bytes-exactly 'adler-checksum 4 i) 
> ... 
>
> Perhaps you could contribute your adler32 implementation, and it could 
> be used there. (And perhaps that `zlib-inflate` function deserves being 
> pulled out into a separate module. Hmm.) 
>
> Cheers, 
> Tony 
>

Yes, please do this. I was in need of a zlib-inflate while working on a 
script to inspect Minecraft save data. 

-- 
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/853ecf97-23c9-4602-a0e1-038ddda3a0cdn%40googlegroups.com.


[racket-users] Re: racket2nix

2018-02-19 Thread reilithion
I'm excited for this project! As a user of both Racket and NixOS, I've been 
hoping for something like this to come along for a while. I wish I had more 
time to devote to helping it succeed. I'll probably poke at it a little 
with a small side project and try to give feedback on using 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.


[racket-users] GUI / Framework high-level overview

2017-07-25 Thread reilithion
I'm trying to write my own source-code editor using `racket/gui` and 
`framework`. Things are going well! I love what I've been able to accomplish so 
far, with very little code!

I'm to the point where I'd like to add support for another language besides 
Racket. I've been using `racket:text%` objects so far. They're a nice 
off-the-shelf way to get editors that support Racket syntax highlighting and 
some other nice features. It seems like the idiomatic way to support a new 
language would be to implement a new editor class in the same style. So I 
started looking at the code. And I'm lost.

It's been hard to figure out the intent of the code in lots of places, and I 
don't know where to focus my attention. I need to understand the high-level 
concepts so that the code will make sense.

For example, I see that a surrogate is used in a lot of places. It looks like a 
surrogate is a `text%` object, but I don't know what it is conceptually, or 
whether its job is to hold the text or to display it. I also don't understand 
why it would need to be enabled or disabled.

What is a `set-mode-mixin`? A `color:text-mode%`? Actually, what is a mode?

Is there anywhere the overall architecture built and used in the framework is 
explained at a high level? A guide to extending and using it would also be 
awesome, if such a thing existed.

-- 
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: [racket] Problems using Sandbox and Scribble

2017-07-15 Thread reilithion
This works now. Sadly, I don't remember why I needed it to work.

#lang racket

(require racket/sandbox
 scribble/manual)

(define safe-eval
   (parameterize ([sandbox-namespace-specs
   (append (sandbox-namespace-specs)
   '(scribble/manual scribble/racket))])
 (make-evaluator 'racket/base
 #:requires '(scribble/manual scribble/racket

(pretty-print (racket foo))  ; Gives one output
(pretty-print (safe-eval '(racket foo)))  ; Gives a slightly DIFFERENT output

(para (racket foo))  ; Finishes happily
(para (safe-eval '(racket foo)))  ; 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.


[racket-users] Re: Forwarding syntax or srcloc

2017-07-15 Thread reilithion
Thanks for all the suggestions, everyone! I ended up going with William's 
solution, since it required the least change to the way one will likely use my 
library.

-- 
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] Forwarding syntax or srcloc

2017-07-04 Thread reilithion
I'd like to be able to get source location information from behind two or more 
layers of macros.

I have a macro, call it mk-data, whose job it is to make an internal data 
structure. Among other things, it records a srcloc for later tracking. In 
another module, I have another macro whose job it is to specialize mk-data and 
present a simpler interface.

Unfortunately, the srcloc that gets stored ends up being the location of the 
simplifying macro. Not what I want. I need to somehow forward the srcloc of its 
use-location. Example follows:

a.rkt:
#lang racket
(provide mk-data getloc)
(struct data-internal
  (name x y srcloc)
  #:guard (λ (n x y srcloc struct-name)
(unless (real? x)
  (raise-argument-error 'data-internal "real?" x))
(unless (real? y)
  (raise-argument-error 'data-internal "real?" y))
(values n x y srcloc)))
(define-syntax (mk-data stx)
  (syntax-case stx ()
[(_ name x y)
 #`(data-internal name x y (srcloc #,(syntax-source stx)
   #,(syntax-line stx)
   #,(syntax-column stx)
   #,(syntax-position stx)
   #,(syntax-span stx)))]))
(define (getloc d) (srcloc->string (data-internal-srcloc d)))

b.rkt:
#lang racket
(provide simple-data)
(require "a.rkt")
(define-syntax (simple-data stx)
  (syntax-case stx ()
[(_ name x)
 #'(mk-data 'name x 42)]))

c.rkt:
#lang racket
(require "a.rkt" "b.rkt")
(getloc (simple-data unlucky 262))

I want the result in c.rkt to be "c.rkt:3:9" or so, rather than "b.rkt:7:7".
I realize I could probably make the simple-data macro in b.rkt a bit more 
sophisticated to help matters, but I'm really resisting doing so. There are 
going to be a lot of macros like simple-data, and some of them may be written 
by users, so I'd like to make it as simple as possible to make new ones. I'd 
rather change mk-data, even if it means making it significantly more complex. 
What's the best way to accomplish this?

-- 
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] Raising multiple exceptions at once

2017-07-04 Thread reilithion
Hi,

I have a program that uses multiple threads and may have several exceptions 
happen more-or-less at once. I'd like to be able to raise them all together and 
have all of them printed to stderr, including stack traces.

I first tried just throwing them in a list and raising the list, but of course 
that doesn't come out very pretty (only one thread failed in this example):

uncaught exception: (list (exn:fail:task-failed "I failed.\n" 
# ...))

Next, I thought I'd try looping through the exceptions and using exn->string. 
But it seems this function doesn't give me stack traces or any kind of source 
location information.

It occurred to me to try to use the same mechanism that the REPL does, but I 
don't know anything about it, and I found the documentation on prompts and 
aborts to be a bit confusing. I didn't grok how the REPL used them to pull off 
its magic trick. What's the right way to go about this?

Thanks,
Lucas

-- 
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: Looking for suggestion on accumulating the paths of Graph from HtDP

2016-01-30 Thread reilithion
In fact, this solution isn't even quite correct modulo the representation 
problem you pointed out yet. It fails on some input graphs:

```
(define problem-graph
'((A (B C E)) 
  (B (E))
  (C (F
```

As for your nesting list problem, I believe it will nest things deeper the 
longer the path. The problem is in the interplay between `map` and 
`find-paths`. `find-paths` returns a list, by applying its first argument to 
each element of its second argument. But `find-paths` produces a list as its 
result. What happens when each result in a map is, itself, a list?

If you're still having trouble seeing the source of the problem, try writing 
down the type of each argument to and result from the functions `find-paths`, 
`find-paths/all`, and `neighbors`. For example, the type of `origin` should be 
`symbol`, the type of `path` should be `(listof symbol)`, the type of `G` can 
just be `graph` (for simplicity), and the return type of `neighbors` should be 
`(listof symbol)`. You're going to run into trouble trying to match a couple of 
types that really ought to match.

- Lucas Paul

On Saturday, January 30, 2016 at 9:29:56 PM UTC-7, liweijian wrote:
> HtDP taught us how to check if there exists path(s) from one node to another.
> 
> I tried to implement accumulating all the paths between two nodes as:
> 
> ```racket
> (define (find-paths origin dest G path)
>   (cond
> [(equal? origin dest) (reverse (cons dest path))]
> [else
>  (find-paths/all (neighbors origin G) dest G (cons origin path))]))
> 
> (define (find-paths/all lons dest G path)
>   (cond
> [(empty? lons) '(#f)]
> [else
>  (map (λ (n) (find-paths n dest G path)) lons)]))
> ```
> 
> However, when I tested it by
> 
> ```racket
> (define sample-graph
>   '((A (B E))
> (B (E
> 
> (define (neighbors origination G)
>   (cadr (assoc origination G)))
> 
> (find-paths 'A 'E sample-graph '())
> ```
> 
> The answer is: '(((A B E)) (A E))
> 
> In order to get the right answer, I have to write another `flatten` function 
> as:
> 
> ```racket
> (define (flatten-path lop)
>   (cond
> [(empty? lop) empty]
> [(not (list? (caar lop))) (cons (first lop) (flatten-path (rest lop)))]
> [else
>  (append (flatten-path (first lop)) (flatten-path (rest lop)))]))
> 
> (filter (λ (path) (not (boolean? (car path (flatten-path (find-paths 'A 
> 'E sample-graph '(
> ```
> 
> And now it works.
> 
> I was wondering if maybe I could improve 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.


[racket-users] Using local-expand to mostly expand a module?

2016-01-29 Thread reilithion
I'm trying to make a little EDSL that has one form that is special and needs to 
be collected and later processed. I want to allow a user of the EDSL to write a 
macro that expands to the special form. I have a module-begin that (so far) 
looks like this:

(define-syntax (module-begin stx)
  (syntax-parse stx
((_ module-contents ...)
 (let-values
  ([(tasks other)
(partition
 (syntax-parser #:literals (task-internal) ((task-internal _ ...) #t) 
(_ #f))
 (rest
  ;; Problems start here
  (syntax->list
   (local-expand
#'(#%plain-module-begin module-contents ...)
'module-begin
(list #'task-internal #'module* #'#%app)])
  #`(#%module-begin
 #,@other
 (define all-tasks (list #,@tasks))
 (process all-tasks))

If I don't bother with the local-expand and just use (rest (syntax->list stx)), 
it works basically fine but won't treat macros that expand to task-internal 
specially. I tried mapping local-expand over (syntax->list stx), but that led 
to strange errors when I tried to define macros within the EDSL.

This current implementation fails because it expands too much too soon. A macro 
will happily expand into (task-internal args ...), then (task-internal1 args 
...), then (#%app task-internal1 args ...), and then the call to partition 
won't see what it's expecting (in fact, I think it CAN'T see what it needs to, 
because I suspect the local-expand of the #%plain-module-begin effectively 
hides the task-internal identifier).

I added a bunch of stuff to the stop-ids list, hoping it would bail before 
transforming task-internal beyond recognition, but nothing I added seemed to 
work.

I also tried calling local-expand on #'(begin module-contexts ...) with the 
'top-level context-v, but of course begin is automatically added to the 
stop-ids list and local-expand stops right away.

Can I somehow get local-expand to only mostly expand a module? How do I do what 
I'm trying to do here?

Thanks!
Lucas Paul

-- 
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] Odd behavior of syntax-case

2016-01-28 Thread reilithion
Thanks for the explanation! Does this mean that syntax-case simply doesn't have 
a way to write a pattern that matches save-the-world anywhere in the list? I'm 
also curious why these two constructs have such different pattern matchers. Is 
it just that syntax-parse is newer and will one day supplant syntax-case?

On Thursday, January 28, 2016 at 6:06:31 AM UTC-7, Matthew Flatt wrote:
> The pattern matcher in `syntax-case` is less powerful than the one in
> `syntax-parse`. The pattern
> 
>   (_ trash-left ... save-the-world . trash-right)
> 
> can match `save-the-world` only against the last item in a list --- or
> against the first of the last pair for a non-list.
> 
> 
> With `syntax-parse`, as you've probably noticed, you can write
> 
>   (_ trash-left ... save-the-world trash-right ...)
> 
> and it will find a match in all of your examples. With `syntax-case`,
> that pattern is not even allowed.
> 
> 
> At Wed, 27 Jan 2016 23:11:25 -0800 (PST), reilithion wrote:
> > I was trying to write a macro today (I'm not too good at writing macros 
> > yet) 
> > and I ran up against a wall when I realized that syntax-case wasn't 
> > behaving 
> > the way I expected. I boiled down the behavior to the following test case:
> > 
> > #lang racket/base
> > 
> > (require (for-syntax racket/base))
> > 
> > ;; Intended behavior:
> > ;; Break the world unless save-the-world is
> > ;; ANYWHERE in the list of arguments
> > (define-syntax (break-the-world stx)
> >   (syntax-case stx (save-the-world)
> > [(_ trash-left ... save-the-world . trash-right)
> >  #'(begin (display 'hooray) (newline))]
> > [_ #'(error "The world is broken!")]))
> > 
> > (break-the-world save-the-world)
> > (break-the-world 'trash1 save-the-world)
> > (break-the-world save-the-world 'trash2)
> > (break-the-world 'trash1 save-the-world 'trash2)
> > 
> > The first two expansions of break-the-world result in "hooray". The last 
> > two, 
> > on the other hand, break the world. I gather that 'trash2 is not being 
> > matched 
> > by the ". trash-right" part of my pattern. What I don't understand is why, 
> > especially when this kind of thing seems to work if I use syntax-parse 
> > instead.
> > 
> > Is there a more idiomatic way of matching a pattern anywhere in a list?
> > 
> > Thanks!
> > Lucas Paul

-- 
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] Odd behavior of syntax-case

2016-01-27 Thread reilithion
I was trying to write a macro today (I'm not too good at writing macros yet) 
and I ran up against a wall when I realized that syntax-case wasn't behaving 
the way I expected. I boiled down the behavior to the following test case:

#lang racket/base

(require (for-syntax racket/base))

;; Intended behavior:
;; Break the world unless save-the-world is
;; ANYWHERE in the list of arguments
(define-syntax (break-the-world stx)
  (syntax-case stx (save-the-world)
[(_ trash-left ... save-the-world . trash-right)
 #'(begin (display 'hooray) (newline))]
[_ #'(error "The world is broken!")]))

(break-the-world save-the-world)
(break-the-world 'trash1 save-the-world)
(break-the-world save-the-world 'trash2)
(break-the-world 'trash1 save-the-world 'trash2)

The first two expansions of break-the-world result in "hooray". The last two, 
on the other hand, break the world. I gather that 'trash2 is not being matched 
by the ". trash-right" part of my pattern. What I don't understand is why, 
especially when this kind of thing seems to work if I use syntax-parse instead.

Is there a more idiomatic way of matching a pattern anywhere in a list?

Thanks!
Lucas Paul

-- 
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.