Re: [racket-users] inspecting inferred types in typed racket

2018-08-13 Thread dicknes18
Hello, I have a similar need (in terms of processing the expanded program 
from typed racket) and came across this post. Unfortunately I am a racket 
newbie and I don't quite understand the code in typed-racket/core.rkt. Can 
you please give me some pointers as to what code I should copy/paste? I am 
hoping that I can do something like:

(define-syntax-rule (my-module-begin prog ...)
  (#%module-begin 
(let [(expanded (call-typed-racket-to-typecheck prog ...)] 
(my-processor expanded) ))

(define (my-processor prog ...)
  (if (query-return-type-from-typed-racket prog integer?) (println "int") 
;similarly for other cases
))

Any suggestions on how I can implement call-typed-racket-to-typecheck and 
query-return-type-from-typed-racket?

-D

On Thursday, August 9, 2018 at 7:43:38 PM UTC-7, Ben Greenman wrote:
>
> Typed Racket first runs the macro expander, and then type checks the 
> expanded program. 
>
> If your implementation can type check an expanded program too, then 
> you can probably get started by copy/pasting typed racket's 
> #%module-begin and inserting a new pass over the program just after 
> the optimizer. Here's one place to get started looking for what to 
> re-use:* 
>
> https://github.com/racket/typed-racket/blob/master/typed-racket-lib/typed-racket/core.rkt#L34
>  
>
> If your implementation wants to type check the surface syntax of a 
> program, then maybe you can hack something together using the above 
> strategy and the source-syntax library: 
> http://docs.racket-lang.org/source-syntax/index.html 
>
>
> * I think it'd be nice if typed racket provided an "expand + 
> type-check" function that other #langs could re-use, but AFAIK it 
> doesn't yet 
>

-- 
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] Modify Scribble HTML for integration with site

2018-08-13 Thread Matthew Flatt
The documentation at

  http://docs.racket-lang.org/

gets a Racket logo through a some JavaScript that is registered by
"doc-site.js":

  http://docs.racket-lang.org/doc-site.js

Granted, it's awkward to me to rely on a dynamic conversion of the page
content to add an essentially static feature. But this is a general
strategy, and browsers seem to handle it well.

At Mon, 13 Aug 2018 09:14:18 -0700 (PDT), "'Joel Dueck' via Racket Users" wrote:
> I would like to include some scribble/manual docs as part of a larger web 
> site, and would like to provide some extra navigation links for the reader 
> so they can see “how to get back out again”.
> 
> Is there a facility within Scribble for augmenting the HTML just after the 
> beginning of the  tag?
> 
> I see there are ways to supplement the CSS and the content of . I can 
> also specify a prefix file but when targeting HTML it seems this is only 
> used for the doctype and nothing else. I've done a bunch of searching, 
> can’t see that this has ever come up before!
> 
> If nothing else I have the option of displaying the Scribble pages within 
> an iframe, but I'd prefer not to do 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.

-- 
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] Modify Scribble HTML for integration with site

2018-08-13 Thread 'Joel Dueck' via Racket Users
I would like to include some scribble/manual docs as part of a larger web 
site, and would like to provide some extra navigation links for the reader 
so they can see “how to get back out again”.

Is there a facility within Scribble for augmenting the HTML just after the 
beginning of the  tag?

I see there are ways to supplement the CSS and the content of . I can 
also specify a prefix file but when targeting HTML it seems this is only 
used for the doctype and nothing else. I've done a bunch of searching, 
can’t see that this has ever come up before!

If nothing else I have the option of displaying the Scribble pages within 
an iframe, but I'd prefer not to do 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.


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

2018-08-13 Thread George Neuner



On 8/13/2018 10:02 AM, 'Paulo Matos' via Racket Users wrote

On 11/08/18 19:41, Sam Tobin-Hochstadt wrote:
> 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. 


Is this something that will change with Racket-on-Chez? i.e. Racket will
then use the Chez optimizer to generate machine code?


Racket's function call convention is heavier than C's because it has to 
deal with the possibility that functions may be redefined at runtime, or 
may be overloaded ... things C does not have to deal with.  The same 
function may have multiple entry points depending on number of 
arguments, or presence of keywords, etc.  And functions that may be 
redefined must be called indirectly to avoid (re)patching every call 
site when/if the definition changes.  These things make (average) 
function calling in Racket slower than in C.


It is expected that the Chez compiler will do a better job at optimizing 
code, but it can't overcome differences in call semantics.  If you do 
something "schemely" with your functions, then you WILL pay the price 
for it.


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.
For more options, visit https://groups.google.com/d/optout.


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

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



On 11/08/18 19:41, Sam Tobin-Hochstadt wrote:
> 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.
> 

Is this something that will change with Racket-on-Chez? i.e. Racket will
then use the Chez optimizer to generate machine code?

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

Understood, that's what I wanted to know.

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

Wow,didn't know about sham. Thanks for the reference.

> 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   

Re: [racket-users] Re: how to show raco full (non-abbreviated) error messages

2018-08-13 Thread Greg Hendershott
p.s. You could run using errortrace. Although the lambda inferred name
is still elided, the errortrace context should still have a useful
location, which M-x next-error can find if you do it a second time. As
below:

racket -l errortrace -t
srclocasdfasdfaaa.rkt
map: argument mismatch;
 the given procedure's expected number of arguments does not match
 the given number of lists
  given procedure: ....rkt:10:7
  expected: 1
  given: 2
  errortrace...:
   
/tmp/srclocasdfasdfaaa.rkt:10:2:
(map (lambda (x) (/ x 1)) (list 1 2 3) (list 1 2 3))
  context...:
   
/tmp/srclocasdfasdfaaa.rkt:
[running body]

p.p.s. There are still ways Racket can hide paths you might find
useful for Emac's next-error -- such as replacing a long path with
"" or "". In racket-mode for Emacs, I use a custom
error-display-handler to catch such lossy transforms and "undo" them:
https://github.com/greghendershott/racket-mode/blob/master/error.rkt

Also in racket-mode, if you C-c C-c to racket-run and get an unhelpful
error context, you can C-u C-c C-c to rerun again with full errortrace
context.  (You can also set racket-error-level to 'high to run with
errortrace all the time; the gotcha is your program will run more
slowly.)


On Mon, Aug 13, 2018 at 1:25 AM Greg Hendershott
 wrote:
>
> > given procedure: ...amm-3.1/util.scm:58:6
>
> It seems you had something like `(map (lambda (x) x) (list 1 2 3)
> (list 1 2 3))` and the error message wants to show the name of the
> function.
>
> What is the name of an anonymous function?  That sounds like a Zen
> koan. But there is an automatically inferred name, using the source
> location:
>
>   https://docs.racket-lang.org/reference/syntax-model.html#(part._infernames)
>
> So `(object-name (lambda (x) x))` is something like
> `'/path/to/file.rkt:11:22`.  But it seems to be elided for
> /somewhat/long/pathname/for/file.rkt.
>
> How to avoid this? I suppose you could do (procedure-rename (lambda
> (x) x) 'shorter-name). But then you might as well just `define` a
> named function or bind the lambda to a value using `let`.

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