[racket-users] is there a way to syntax-local-lift- something into a define-syntax?

2016-10-08 Thread Stephen Chang
I'm trying to write a provide transformer that wraps a provided
identifier and then provides that instead.

For example,
#lang racket
(require (for-syntax syntax/parse racket/provide-transform))

(define-syntax wrapped-out
  (make-provide-pre-transformer
   (lambda (stx modes)
 (syntax-parse stx
   [(_ f)
#:with wrapped-f
(syntax-local-lift-expression
 #'(lambda args (display "applying ") (displayln 'f)
(apply f args)))
(pre-expand-export
 #'(rename-out [wrapped-f f]) modes)]

(provide (wrapped-out +))

A program requiring my module and using addition will print "applying +".

But I actually want to wrap f with a macro. Is this possible? (Is this
an XY 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.
For more options, visit https://groups.google.com/d/optout.


[racket-users] holiday season project idea: crobots-like game

2016-10-08 Thread Neil Van Dyke
The November through January school break(s), in the US and elsewhere, 
are a good time for students to get in some significant self-directed 
programming projects.


One fun idea, which might be especially interesting to do in Racket in 
particular, is to implement a game inspired by the late-'80s Crobots 
fighting programs simulator: https://en.wikipedia.org/wiki/Crobots


Imagine having a "#lang rrobots" in which to write a fighting robot 
program, using the full Racket language plus a set of Rrobots procedures 
for sensors and effectors.  A user can write and refine this program in 
DrRacket, with a simulator to fight against other robots.  The other 
robot are are just other "#lang rrobots" programs, perhaps bundled with 
Rrobots, or perhaps being developed actively by your friend in their own 
DrScheme.


One of the technical challenges is making sure that the allocation of 
compute power is fair.  Maybe you structure the computation into atomic 
simulation steps (so each robot can do however much computation it needs 
for its next effecting operation, without being at a timing disadvantage 
to a robot that shoots first and computes later).  Or maybe you make it 
more real-time (but all the sensing and effecting operations take a 
relatively long time, so a robot can probably afford to do some 
expensive AI computation before invoking an effector).


If you are opposed philosophically to the use of Racket in armed 
conflict, then the programs could instead be about fuzzy bunnies giving 
each other hugs.


--
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] Constructing unicode surrogates

2016-10-08 Thread Jens Axel Søgaard
2016-10-08 20:00 GMT+02:00 Ryan Culpepper :

> Does one of the `string-normalize-*` functions do what you want?
>

No. I am basically implementing the part of the reader that lexes string
literals.
I want to allow full Racket syntax in the string literals in my infix
package.
One solution is to use (read (open-input-string lexeme)) but I am afraid
that will
be slow.

The job is therefore to turn "\\ud800\\udc00" into "\ud800\udc00" (the
latter a legal string literal).

Since

(string (integer->char (string->number "d800" 16))
  (integer->char (string->number "dc00" 16)))

produces the error

integer->char: contract violation
  expected: (and/c (integer-in 0 #x10) (not/c (integer-in #xD800
#xDFFF)))
  given: 55296

it is necessary to produce the character directly.

/Jens Axel

-- 
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] Constructing unicode surrogates

2016-10-08 Thread Jens Axel Søgaard
Thanks, I can work with that.

/Jens Axel


2016-10-08 19:44 GMT+02:00 Jon Zeppieri :

>
>
> On Sat, Oct 8, 2016 at 1:06 PM, Jens Axel Søgaard 
> wrote:
>
>> Hi All,
>>
>> The following interaction shows how the reader can be used to construct a
>> surrogate character:
>>
>> > (string-ref "\ud800\udc00" 0)
>> #\
>>
>> Given the two hexadecimal numbers d800 and dc00 how do I
>> construct the surrogate character directly?
>>
>> /Jens Axel
>>
>>
> I think you have to do the arithmetic yourself. Something like:
>
> (define (utf-16-surrogate-pair->char hi lo)
>   (integer->char
>(+ #x1
>   (arithmetic-shift (bitwise-and hi #x03ff) 10)
>   (bitwise-and lo #x03ff
>
>
>
>


-- 
-- 
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] Constructing unicode surrogates

2016-10-08 Thread Ryan Culpepper

Does one of the `string-normalize-*` functions do what you want?

Ryan


On 10/08/2016 01:06 PM, Jens Axel Søgaard wrote:

Hi All,

The following interaction shows how the reader can be used to construct
a surrogate character:

 > (string-ref "\ud800\udc00" 0)
 #\

Given the two hexadecimal numbers d800 and dc00 how do I
construct the surrogate character directly?

/Jens Axel

--
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] Constructing unicode surrogates

2016-10-08 Thread Jon Zeppieri
On Sat, Oct 8, 2016 at 1:06 PM, Jens Axel Søgaard 
wrote:

> Hi All,
>
> The following interaction shows how the reader can be used to construct a
> surrogate character:
>
> > (string-ref "\ud800\udc00" 0)
> #\
>
> Given the two hexadecimal numbers d800 and dc00 how do I
> construct the surrogate character directly?
>
> /Jens Axel
>
>
I think you have to do the arithmetic yourself. Something like:

(define (utf-16-surrogate-pair->char hi lo)
  (integer->char
   (+ #x1
  (arithmetic-shift (bitwise-and hi #x03ff) 10)
  (bitwise-and lo #x03ff

-- 
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] Constructing unicode surrogates

2016-10-08 Thread Jens Axel Søgaard
Hi All,

The following interaction shows how the reader can be used to construct a
surrogate character:

> (string-ref "\ud800\udc00" 0)
#\

Given the two hexadecimal numbers d800 and dc00 how do I
construct the surrogate character directly?

/Jens Axel

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