Re: [racket-users] Bitmaps and Canvas sizes

2018-08-11 Thread David Vanderson
Usually you adjust the drawing context's scale.  Something like (untested):

(define bm (read-bitmap ...))
(define dc (send image-box get-dc))
(define t (send dc get-transformation))  ; save old scale
(send dc scale
  (/ (send image-box get-width) (send bm get-width))
  (/ (send image-box get-height) (send bm get-height)))
(send dc draw-bitmap bm 0 0)
(send dc set-transformation t)  ; restore old scale

If you want to create a new bitmap with the exact size you want, then
you create a new bitmap and use the same strategy:
(define new-bm (make-bitmap w h))
(define dc (send new-bm get-dc))
; same as above

Does that help?
Dave

On Sat, Aug 11, 2018 at 9:48 PM,   wrote:
> (define image-box
>   (new canvas% [parent frame]
>[min-width 300]
>[min-height 300]))
>
> I'm still trying to figure out how the racket/gui library works but I'm
> having some difficulty understanding how to have an image fill a canvas.
>
> I'd like for instance to have a canvas in my gui that is 300x300 and have
> any image I load resized to fit those dimensions.
>
> (send (send image-box get-dc)
>   draw-bitmap
>   (read-bitmap (string->path (send list-box get-string
> select)))
>   0 0))
>
> Here I have some quickly thrown together code for selecting a list of
> pathnames to images from a list-box.  The images are all different sizes and
> usually end up exceeding the canvas size.
>
> I've looked around the documentation, especially in the racket/draw module
> but I can't find anything beyond a "scale" which doesn't really seem all
> that helpful.  If anyone knows how to change images to certain sizes that'd
> be helpful.  I tried looking at racket/pict too but that doesn't seem to
> have anyway to absolutely set a image's dimensions.
>
> Thanks!
>
> --
> 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] Bitmaps and Canvas sizes

2018-08-11 Thread silverfire675
(define image-box
  (new canvas% [parent frame]
   [min-width 300]
   [min-height 300]))

I'm still trying to figure out how the racket/gui library works but I'm 
having some difficulty understanding how to have an image fill a canvas.

I'd like for instance to have a canvas in my gui that is 300x300 and have 
any image I load resized to fit those dimensions.

(send (send image-box get-dc)
  draw-bitmap
  (read-bitmap (string->path (send list-box get-string 
select)))
  0 0))

Here I have some quickly thrown together code for selecting a list of 
pathnames to images from a list-box.  The images are all different sizes 
and usually end up exceeding the canvas size.

I've looked around the documentation, especially in the racket/draw module 
but I can't find anything beyond a "scale" which doesn't really seem all 
that helpful.  If anyone knows how to change images to certain sizes that'd 
be helpful.  I tried looking at racket/pict too but that doesn't seem to 
have anyway to absolutely set a image's dimensions.

Thanks!

-- 
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: Question about style

2018-08-11 Thread Andrew J
I typically use either threading or composition...

(require threading)
(define (foo x)
  (~> x 
f g h bar))

or

(define (foo x)
  ((compose bar h g f) x)


A.

On Sunday, 12 August 2018 00:11:19 UTC+10, 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.


Re: bug#30680: [racket-users] Using Racket's raco on on Guix(SD)

2018-08-11 Thread Christopher Lemmer Webber
Nils Gillmann writes:

> Christopher Lemmer Webber transcribed 3.3K bytes:

>> BTW, some examples of packages where I've had trouble, in case it helps
>> with testing:
>> 
>>  - Raart
>>  - Gregor
>>  - crypto (seemed to work last time, not sure why it wasn't working before)
>> 
>> Though at this point I also can't do just "raco setup" on a local
>> package either, but maybe resolving this issue will fix that.
>> 
> From what I've learned in the last couple of hours, the last problem could
> be due to leftovers in your raco / dotRacket folder from an older 
> installation.

Would be nice if it were so simple, but:

Having removed ~/.racket, try:

$ git clone https://github.com/cwebber/racket-linkeddata.git
$ cd racket-linkeddata/linkeddata

cwebber@jasmine:~/devel/racket-linkeddata/linkeddata$ raco setup
open-output-file: cannot open output file
  path: 
/gnu/store/jx0bkmaafb8fq0mqs5ywgnxq8rbpn8j1-racket-6.12/share/racket/collects/openssl/compiled/tmp15340298121534029812614
  system error: Read-only file system; errno=30
  context...:
   
/gnu/store/jx0bkmaafb8fq0mqs5ywgnxq8rbpn8j1-racket-6.12/share/racket/collects/racket/private/more-scheme.rkt:261:28
   
/gnu/store/jx0bkmaafb8fq0mqs5ywgnxq8rbpn8j1-racket-6.12/share/racket/collects/racket/file.rkt:199:0:
 call-with-atomic-output-file20
   
/gnu/store/jx0bkmaafb8fq0mqs5ywgnxq8rbpn8j1-racket-6.12/share/racket/collects/compiler/cm.rkt:363:0:
 compile-zo*
   
/gnu/store/jx0bkmaafb8fq0mqs5ywgnxq8rbpn8j1-racket-6.12/share/racket/collects/compiler/cm.rkt:572:26
   
/gnu/store/jx0bkmaafb8fq0mqs5ywgnxq8rbpn8j1-racket-6.12/share/racket/collects/compiler/cm.rkt:564:42
   
/gnu/store/jx0bkmaafb8fq0mqs5ywgnxq8rbpn8j1-racket-6.12/share/racket/collects/compiler/cm.rkt:635:0:
 compile-root
   
/gnu/store/jx0bkmaafb8fq0mqs5ywgnxq8rbpn8j1-racket-6.12/share/racket/collects/compiler/cm.rkt:688:15
   
/gnu/store/jx0bkmaafb8fq0mqs5ywgnxq8rbpn8j1-racket-6.12/share/racket/collects/compiler/cm.rkt:635:0:
 compile-root
   
/gnu/store/jx0bkmaafb8fq0mqs5ywgnxq8rbpn8j1-racket-6.12/share/racket/collects/compiler/cm.rkt:688:15
   
/gnu/store/jx0bkmaafb8fq0mqs5ywgnxq8rbpn8j1-racket-6.12/share/racket/collects/compiler/cm.rkt:635:0:
 compile-root
   
/gnu/store/jx0bkmaafb8fq0mqs5ywgnxq8rbpn8j1-racket-6.12/share/racket/collects/compiler/cm.rkt:688:15
   
/gnu/store/jx0bkmaafb8fq0mqs5ywgnxq8rbpn8j1-racket-6.12/share/racket/collects/compiler/cm.rkt:635:0:
 compile-root
   
/gnu/store/jx0bkmaafb8fq0mqs5ywgnxq8rbpn8j1-racket-6.12/share/racket/collects/compiler/cm.rkt:782:4:
 compilation-manager-load-handler
   standard-module-name-resolver
   
/gnu/store/jx0bkmaafb8fq0mqs5ywgnxq8rbpn8j1-racket-6.12/share/racket/collects/setup/main.rkt:
 [running body]
   
/gnu/store/jx0bkmaafb8fq0mqs5ywgnxq8rbpn8j1-racket-6.12/share/racket/collects/raco/main.rkt:
 [running body]
cwebber@jasmine:~/devel/racket-linkeddata/linkeddata$ 


Likewise, Gregor and Raart do not install:

$ mv ~/.racket ~/.racket-borked
$ raco pkg install gregor   # lots of errors during install
$ racket
racket@> (require gregor)
explode-path: contract violation
  expected: (or/c path-for-some-system? path-string?)
  given: #f
  context...:
   
/gnu/store/jx0bkmaafb8fq0mqs5ywgnxq8rbpn8j1-racket-6.12/share/racket/collects/racket/path.rkt:116:0:
 do-explode-path
   
/gnu/store/jx0bkmaafb8fq0mqs5ywgnxq8rbpn8j1-racket-6.12/share/racket/collects/racket/path.rkt:126:0:
 find-relative-path7
   /home/cwebber/.racket/6.12/pkgs/tzinfo/tzinfo/private/zoneinfo.rkt:117:2: 
for-loop
   /home/cwebber/.racket/6.12/pkgs/tzinfo/tzinfo/private/zoneinfo.rkt:107:0: 
read-tzids
   /home/cwebber/.racket/6.12/pkgs/tzinfo/tzinfo/private/zoneinfo.rkt:70:0: 
make-zoneinfo-source
   
/gnu/store/jx0bkmaafb8fq0mqs5ywgnxq8rbpn8j1-racket-6.12/share/racket/collects/racket/contract/private/arrow-val-first.rkt:388:18
   /home/cwebber/.racket/6.12/pkgs/tzinfo/tzinfo/main.rkt:63:0: system-tzid
   
/gnu/store/jx0bkmaafb8fq0mqs5ywgnxq8rbpn8j1-racket-6.12/share/racket/collects/racket/contract/private/arrow-val-first.rkt:388:18
   /home/cwebber/.racket/6.12/pkgs/gregor-lib/gregor/private/moment.rkt: 
[running body]
   /home/cwebber/.racket/6.12/pkgs/gregor-lib/gregor/private/generics.rkt: 
[traversing imports]
   /home/cwebber/.racket/6.12/pkgs/gregor-lib/gregor/private/clock.rkt: 
[traversing imports]
   /home/cwebber/.racket/6.12/pkgs/gregor-lib/gregor/main.rkt: [traversing 
imports]
   
/gnu/store/jx0bkmaafb8fq0mqs5ywgnxq8rbpn8j1-racket-6.12/share/racket/collects/racket/private/misc.rkt:88:7

... install raart, lots of "cannot open output file" error messages ...
racket@> (require raart)
get-module-code: no such file: 
#
  context...:
   
/gnu/store/jx0bkmaafb8fq0mqs5ywgnxq8rbpn8j1-racket-6.12/share/racket/collects/syntax/modcode.rkt:120:0:
 get-module-path54
   
/gnu/store/jx0bkmaafb8fq0mqs5ywgnxq8rbpn8j1-racket-6.12/share/racket/collects/syntax/modcode.rkt:225:0:
 get-module-code82
   
/gnu/store/jx0bkmaafb8fq0mqs5ywgnxq8rbpn8j1-racket-6.12/share/racket/collects/racket/pri

Re: bug#30680: [racket-users] Using Racket's raco on on Guix(SD)

2018-08-11 Thread Christopher Lemmer Webber
Timothy Sample writes:

> Christopher Lemmer Webber  writes:
>
>> Konrad Hinsen writes:
>>
>>> In my tests, all packages ended up working, but performance is indeed
>>> worse than with a Racket installation outside of Guix.
>>>
>>> It would be nice if someone with more knowledge of Racket internals
>>> could give a hint or two for debugging this issue!
>>>
>>> Konrad.
>>
>> I'm posting a bug bounty on this issue: if someone can fix this I will
>> pay them $250 USD.  I don't have the time or knowledge enough of Racket
>> internals to do so myself.
>
> I have discovered a few things, but I’m not sure how to fix the
> underlying problem(s).
>
> The reason Racket is trying to recompile the OpenSSL files is because of
> a hash mismatch.  This can be seen by enabling debugging output:
>
> $ PLTSTDERR=debug raco setup openssl
>
> Which says a lot of things, but most interestingly it says:
>
> 
> ...
> compiler/cm: checking: 
> /gnu/store/jx0bkmaafb8fq0mqs5ywgnxq8rbpn8j1-racket-6.12/share/racket/collects/openssl/libcrypto.rkt
> compiler/cm: different src hash... (5d9ca57f3e267d956c7b5e62578467beb8ccc1d2 
> 4d21ac412723fbf33f97669c2f73f0e9367f4510)
> compiler/cm: maybe-compile-zo starting 
> /gnu/store/jx0bkmaafb8fq0mqs5ywgnxq8rbpn8j1-racket-6.12/share/racket/collects/openssl/libcrypto.rkt
> compiler/cm:   start-compile: 
> /gnu/store/jx0bkmaafb8fq0mqs5ywgnxq8rbpn8j1-racket-6.12/share/racket/collects/openssl/libcrypto.rkt
> compiler/cm:   compiling 
> /gnu/store/jx0bkmaafb8fq0mqs5ywgnxq8rbpn8j1-racket-6.12/share/racket/collects/openssl/libcrypto.rkt
> open-output-file: cannot open output file
>   path: 
> /gnu/store/jx0bkmaafb8fq0mqs5ywgnxq8rbpn8j1-racket-6.12/share/racket/collects/openssl/compiled/tmp15340167971534016797570
>   system error: Read-only file system; errno=30
>   context...:
> ...
> 
>
> This hash mismatch is caused by grafting.  When the package is built,
> the path to OpenSSL gets hard-coded in a source file.  The SHA-1 hash
> for this file is stored in its “.dep” file.  When the output is
> grafted, the source file gets updated with a new OpenSSL path, but the
> hash does not get updated.  This makes Racket think that the cached
> bytecode file is incorrect (even though it was likely grafted too),
> and it tries to recompile it.  It fails because it tries to write this
> new bytecode file to the store.

Interesting... I hadn't even considered grafting.  (I still wonder why
it's even trying to open *any* file in the store for output though...)

> I double checked this by trying with an ungrafted Racket, and got better
> results.  (There was still a warning about writing to the store, but it
> seemed less significant.)

Cool!

> The only thing I can think of for a fix would be to patch Racket to be
> more lenient with bytecode files in the store.  That is, ignore hash
> mismatches in store-files.  I might give this a try later tonight if
> nobody has any better ideas.
>
> -- Tim

BTW, some examples of packages where I've had trouble, in case it helps
with testing:

 - Raart
 - Gregor
 - crypto (seemed to work last time, not sure why it wasn't working before)

Though at this point I also can't do just "raco setup" on a local
package either, but maybe resolving this issue will fix 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.


Re: [racket-users] C level bit manipulation - Racket Manifesto

2018-08-11 Thread Sam Tobin-Hochstadt
There are basically two differences between the `unsafe-lsb` function
in Racket and the C one:
 - the Racket calling convention vs the C calling convention
 - the instruction used to perform the LSB calculation

For a variety of reasons Racket's function calling convention is more
heavyweight than C's, but if that code is inlined into some larger
function that will go away (as it would in C). The simpler instruction
used by the C compiler is because the C compiler recognizes that
pattern of bitwise and, whereas the Racket JIT does the obvious `and`.
That could of course be fixed in the JIT, although it's not clear how
much of a win it is.

More broadly, whether Racket supports "C-level" programming depends on
what you mean. If it means "can I use the same APIs and access the
same bits I would in C", then you certainly can, although often you
need to use the FFI to do so. That's what the Racket Manifesto means.
If it means "can I generate the same assembly instructions or get the
same maximum performance from pure Racket code as from C code", then
it isn't true, and you'll need to use some other tools, such as
generating code yourself (see https://github.com/rjnw/sham for an
example).

Sam

On Sat, Aug 11, 2018 at 4:15 AM, 'Paulo Matos' via Racket Users
 wrote:
> Hi,
>
> In http://felleisen.org/matthias/manifesto/, you can read:
> "In support, Racket offers protection mechanisms to implement a full
> language spectrum, from C-level bit manipulation to soundly typed
> extensions."
>
> What are we talking about here when we mention C-level bit manipulation? Is
> this referring to the ffi or some other Racket feature that allows me to
> generate unsafe bit manipulation instructions?
>
> In C, for a bitwise_and of an integer x and 0xff, I get:
> https://godbolt.org/g/gy3ZN9
> bitwise_and:
>   movzx eax, dil
>   ret
>
> In Racket, I tried:
> #lang racket
>
> (require disassemble
>  racket/unsafe/ops)
>
> (define (lsb x)
>   (bitwise-and x #xff))
>
> (disassemble lsb)
>
>0: 488b4808   (mov rcx (mem64+ rax #x8))
>4: 48898bf8ff (mov (mem64+ rbx #x-8) rcx)
>b: 488b4810   (mov rcx (mem64+ rax #x10))
>f: 48898bf0ff (mov (mem64+ rbx #x-10) rcx)
>   16: 4881c3f0ff (add rbx #xfff0)
>   1d: 488b13 (mov rdx (mem64+ rbx))
>   20: 488b5230   (mov rdx (mem64+ rdx #x30))
>   24: 488b4208   (mov rax (mem64+ rdx #x8))
>   28: 488983f8ff (mov (mem64+ rbx #x-8) rax)
>   2f: 48b8a80e484c   (mov rax #x4c480ea8)
>   39: 488b00 (mov rax (mem64+ rax))
>   3c: 488983f0ff (mov (mem64+ rbx #x-10) rax)
>   43: 4881c3f0ff (add rbx #xfff0)
>   4a: 488b4308   (mov rax (mem64+ rbx #x8))
>   4e: f6c001 (test al #x1)
>   51: 0f850f00   (jnz (+ rip #xf))
>   57: 66833831   (cmp (mem16+ rax) #x31)
>   5b: 0f850500   (jnz (+ rip #x5))
>   61: e81e771fb4 (call (+ rip #x-4be088e2))
>   66: e8bb751fb4 (call (+ rip #x-4be08a45))
>   6b: 488b4320   (mov rax (mem64+ rbx #x20))
>   6f: 4883c310   (add rbx #x10)
>   73: f6c001 (test al #x1)
>   76: 0f851400   (jnz (+ rip #x14))
>   7c: ba60fba070 (mov edx #x70a0fb60)
>   81: b9ff01 (mov ecx #x1ff)
>   86: e86e001fb4 (call (+ rip #x-4be0ff92))
>   8b: e90700 (jmp (+ rip #x7))
>   90: 4881e0ff01 (and rax #x1ff)
>   97: 4c8b75c8   (mov r14 (mem64+ rbp #x-38))
>   9b: 4883c428   (add rsp #x28)
>   9f: 5f (pop rdi)
>   a0: 5e (pop rsi)
>   a1: 5b (pop rbx)
>   a2: 5d (pop rbp)
>   a3: c3 (ret)
>
> (define (unsafe-lsb x)
>   (unsafe-fxand x #xff))
>
> (disassemble unsafe-lsb)
>
>0: 488983f8ff (mov (mem64+ rbx #x-8) rax)
>7: 4881c3f8ff (add rbx #xfff8)
>e: 488b4308   (mov rax (mem64+ rbx #x8))
>   12: 4881e0ff01 (and rax #x1ff)
>   19: 4c8b75c8   (mov r14 (mem64+ rbp #x-38))
>   1d: 4883c428   (add rsp #x28)
>   21: 5f (pop rdi)
>   22: 5e (pop rsi)
>   23: 5b (pop rbx)
>   24: 5d 

Re: [racket-users] Question about style

2018-08-11 Thread Deren Dohoda
>
>
>
> 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.
>

I invariably write my code like this. I just think it's easier to
understand two years later. I have a few let-like macros for this reason.
1) print-let /print-let*, for printf-debugging of let forms. 2) andlet /
andlet*, for stopping binding evaluation in a let when the value to bind is
#f (then the whole 'let' expression is #f). Sometimes I use internal
'define's instead, based on feel for heavily-indented code. I rarely try to
write a complicated expression directly without some kind of explanatory
setup. I have tinkered with some other 'let'-like forms but these two in
particular are really useful.

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.


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

2018-08-11 Thread Matthew Butterick

> On Aug 11, 2018, at 9:00 AM, Sage Gerard  wrote:
> 
> 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.

Perhaps consider making a little `racket/koan` language for your exercises that 
includes some extra conveniences. For instance, one way to address your unbound 
identifiers is to redefine `#%top` as shown below. But you could move that into 
`racket/koan`.


#lang racket/base

(require rackunit)

(require (for-syntax racket/base))
(define-syntax (#%top stx)
  (syntax-case stx ()
[(_ . id) (not (identifier-binding #'id)) #'(λ _ (format "unbound 
identifier: ~a" 'id))]
[(_ . id) #'id]))

;; Produce a single struct that passes all assertions.
(let ([p "?"])
  (check-pred racketeer? p)
  (check-pred programmer? p)
  (check-pred struct? p)
  (check-pred procedure? set-programmer-salary!)
  (check-equal? (programmer-confusion-level p) 10)
  (check-equal? (racketeer-desire-for-racket-jobs p) 9001))

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


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

2018-08-11 Thread Sage Gerard
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.


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] Using Racket's raco on on Guix(SD)

2018-08-11 Thread Christopher Lemmer Webber
Konrad Hinsen writes:

> On 22/05/2018 15:42, Christopher Lemmer Webber wrote:
>
>> Unfortunately when I try to install packages with "raco pkg install"
>> I get errors like the following:
>
> I filed a bug report about this problem a while ago:
>
>   https://debbugs.gnu.org/cgi/bugreport.cgi?bug=30680
>
> Quote:
>
>   I traced this back as far as I could by looking at the Racket compiler
>   source code. Compilation generates a temporary file in the same
>   directory where the result is supposed to go. If no errors occur, the
>   temporary file is then renamed to become the output. The partial stack
>   traces point to locations in the code that do a recursive traversal of
>   a library in order to compile everything. Unfortunately, the part that
>   decides where the output goes is not referenced in the stack trace.
>
>> I seem to remember a couple of packages failing altogether, though in
>> the present moment I think the result is bad performance due to not
>> being properly compiled, but I'm not really sure.
>
> In my tests, all packages ended up working, but performance is indeed
> worse than with a Racket installation outside of Guix.
>
> It would be nice if someone with more knowledge of Racket internals
> could give a hint or two for debugging this issue!
>
> Konrad.

I'm posting a bug bounty on this issue: if someone can fix this I will
pay them $250 USD.  I don't have the time or knowledge enough of Racket
internals to do so myself.

-- 
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: Question about style

2018-08-11 Thread Wolfgang Hukriede
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.


[racket-users] Question about style

2018-08-11 Thread Bob Heffernan
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.


[racket-users] application idea: home "cloud" server services in racket

2018-08-11 Thread Neil Van Dyke
Want to work on "libre" privacy-respecting applications in Racket, but 
would rather work on servers, than on handheld/desktop apps, right now?


It would be good to have a home/family (or small business?) "cloud" 
server that one can run at home, and customize in Racket.


Perhaps in the spirit of "https://en.wikipedia.org/wiki/Nextcloud";, but 
providing different services, which do exactly what you want, and in 
Racket rather than PHP.


This could run on a Raspberry Pi, a PC, or some other computers that run 
Linux.


Some service ideas:
* Family file/photo sharing.
* Movie and music streaming to living room.
* Computer backups.
* Wiki for various family topics or small business.
* Calendars.
* Browser bookmarks syncing.
* Email server.
* IRC server.
* Addressbook syncing.
* Private GPS locator server for family member with special needs.
* Home security camera motion-detect and streaming.
* IoT home automation (that's less crazy than off-the-shelf).
* Scratch KVM/Xen instance sandboxes.
* Build server.
* GPU compute server.
* Git server (maybe use off-the-shelf for Git, but running it on same 
hardware as your Racket other services).


These services could mostly be developed independently.  And they don't 
all have to be in Racket, especially not initially.


Another way to look at it is setting up a computer on your home network 
as an ordinary Linux server, and deciding you want to implement (or 
reimplement) some service in Racket.  Then, once more than one such 
service is implemented, you can also look at making it more of a 
polished appliance, with a unified management interface in Racket.  (But 
even if you set up a home Linux server, and then just use non-Racket 
Linux programs, that's still a win.)


Even if you're entirely new to Linux and/or servers, I and others would 
be happy to answer questions.  And if you're new, that's all the more 
reason to start playing with it. :)


If you're totally new to this, and want to start playing right now... 
you could just install minimal Debian GNU/Linux Stable on an old 
PC/laptop or Raspberry Pi you have sitting around, with an SSH server 
running, SSH in from your laptop/desktop to a command prompt, do "wget 
https://mirror.racket-lang.org/installers/7.0/racket-7.0-src-builtpkgs.tgz";, 
and go from there. :)


--
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] C level bit manipulation - Racket Manifesto

2018-08-11 Thread 'Paulo Matos' via Racket Users

Hi,

In http://felleisen.org/matthias/manifesto/, you can read:
"In support, Racket offers protection mechanisms to implement a full 
language spectrum, from C-level bit manipulation to soundly typed 
extensions."


What are we talking about here when we mention C-level bit manipulation? 
Is this referring to the ffi or some other Racket feature that allows me 
to generate unsafe bit manipulation instructions?


In C, for a bitwise_and of an integer x and 0xff, I get: 
https://godbolt.org/g/gy3ZN9

bitwise_and:
  movzx eax, dil
  ret

In Racket, I tried:
#lang racket

(require disassemble
 racket/unsafe/ops)

(define (lsb x)
  (bitwise-and x #xff))

(disassemble lsb)

   0: 488b4808   (mov rcx (mem64+ rax #x8))
   4: 48898bf8ff (mov (mem64+ rbx #x-8) rcx)
   b: 488b4810   (mov rcx (mem64+ rax #x10))
   f: 48898bf0ff (mov (mem64+ rbx #x-10) rcx)
  16: 4881c3f0ff (add rbx #xfff0)
  1d: 488b13 (mov rdx (mem64+ rbx))
  20: 488b5230   (mov rdx (mem64+ rdx #x30))
  24: 488b4208   (mov rax (mem64+ rdx #x8))
  28: 488983f8ff (mov (mem64+ rbx #x-8) rax)
  2f: 48b8a80e484c   (mov rax #x4c480ea8)
  39: 488b00 (mov rax (mem64+ rax))
  3c: 488983f0ff (mov (mem64+ rbx #x-10) rax)
  43: 4881c3f0ff (add rbx #xfff0)
  4a: 488b4308   (mov rax (mem64+ rbx #x8))
  4e: f6c001 (test al #x1)
  51: 0f850f00   (jnz (+ rip #xf))
  57: 66833831   (cmp (mem16+ rax) #x31)
  5b: 0f850500   (jnz (+ rip #x5))
  61: e81e771fb4 (call (+ rip #x-4be088e2))
  66: e8bb751fb4 (call (+ rip #x-4be08a45))
  6b: 488b4320   (mov rax (mem64+ rbx #x20))
  6f: 4883c310   (add rbx #x10)
  73: f6c001 (test al #x1)
  76: 0f851400   (jnz (+ rip #x14))
  7c: ba60fba070 (mov edx #x70a0fb60)
  81: b9ff01 (mov ecx #x1ff)
  86: e86e001fb4 (call (+ rip #x-4be0ff92))
  8b: e90700 (jmp (+ rip #x7))
  90: 4881e0ff01 (and rax #x1ff)
  97: 4c8b75c8   (mov r14 (mem64+ rbp #x-38))
  9b: 4883c428   (add rsp #x28)
  9f: 5f (pop rdi)
  a0: 5e (pop rsi)
  a1: 5b (pop rbx)
  a2: 5d (pop rbp)
  a3: c3 (ret)

(define (unsafe-lsb x)
  (unsafe-fxand x #xff))

(disassemble unsafe-lsb)

   0: 488983f8ff (mov (mem64+ rbx #x-8) rax)
   7: 4881c3f8ff (add rbx #xfff8)
   e: 488b4308   (mov rax (mem64+ rbx #x8))
  12: 4881e0ff01 (and rax #x1ff)
  19: 4c8b75c8   (mov r14 (mem64+ rbp #x-38))
  1d: 4883c428   (add rsp #x28)
  21: 5f (pop rdi)
  22: 5e (pop rsi)
  23: 5b (pop rbx)
  24: 5d (pop rbp)
  25: c3 (ret)

This returns two assembly listings and as expected the unsafe-lsb is 
shorter than the one for lsb but not even close to the one you'd get in 
C. Is there something else in Racket that I might be missing that it 
gives me access to the low level C bit manip constructs besides ffi?


Kind regards,

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