Re: [racket] [The Racket Blog] New comment on Racket.

2010-06-18 Thread Jens Axel Søgaard
2010/6/18 Kyle Smith :
> Kyle Smith has left a new comment on your post "Racket":
>
> Racket is just an organized scheme. The name still brings up connotations of
> something nefarious. What is in a name? I'm good with it if it continues to
> run on a proper OpenBSD platform. Will Apple let something, so expressive as
> ‘Racket’, the honor of being available from their apps store, for use with
> the iPad? Now that would be the app to write, however, unless Apple has
> changed their minds, no interpretive languages, that I'm aware of, have made
> it to iTunes.

In the latest agreement Apple changed the wording to:

Unless otherwise approved by Apple in writing, no interpreted code may
be downloaded or used in an Application except for code that is interpreted
and run by Apple’s Documented APIs and built-in interpreter(s).
Notwithstanding the foregoing, with Apple’s prior written consent,
an Application
may use embedded interpreted code in a limited way if such use is solely
for providing minor features or functionality that are consistent with the
intended and advertised purpose of the Application.

This means that if Racket gets an Arm port, it is possible to use it.
MzScheme used to have an Arm port, but I am somewhat unsure,
whether it has survived the test of time. Has it survived?

-- 
Jens Axel Søgaard
_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/users

Re: [racket] Continuations tutorial

2010-06-20 Thread Jens Axel Søgaard
2010/6/19 Groshev Dmitry :
> Hi. Is there any good continuations tutorial? I've read the reference, but 
> there isn't many examples or explanations. Maybe I'm a bit dumb, but I really 
> need some examples of call/cc / call/ec / dynamic-wind usage to get it right.

Try this one by Dan Friedman:

   http://www.cs.indiana.edu/~dfried/appcont.pdf

I think Friedman has written another (non-ACM) text on continuations,
but I might have
missed at readsceme.org.

-- 
Jens Axel Søgaard
_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/users

[racket] Scribble and MathJax - how to configure the Scribble html renderer to output a custom head

2010-07-02 Thread Jens Axel Søgaard
Hi All,

I'd like to use MathJax with Scribble. The blurb for MathJax is:

Math display for all browsers

MathJaxTM is an open source, Ajax-based math display solution
designed with a goal of consolidating advances in many web
technologies in a single definitive math-on-the-web platform
supporting all major browsers.

Examples: http://www.mathjax.org/preview/preview-tex-examples/


Installing MathJax consists of downloading and unzipping a single folder
(and the fonts) containing some JavaScript source.

In order to use MathJax, I need the Scribble html renderer to output the
following in the head:



Is there a way to get Scribble do this?
I have looked at html-prefix, but it seems this is output before the head.

-- 
Jens Axel Søgaard
_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/users

Re: [racket] keybinding help needed

2010-07-29 Thread Jens Axel Søgaard
Don't forget to look at Kyle's post from 2007.

http://schemekeys.blogspot.com/2007/05/keybinding-101-in-drscheme.html

-- 
Jens Axel Søgaard
_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/users

Re: [racket-users] Moving a Rust/Haskell abstract algebra library to Racket?

2021-01-20 Thread Jens Axel Søgaard
Den ons. 20. jan. 2021 kl. 08.43 skrev Stuart Hungerford <
stuart.hungerf...@gmail.com>:

> On Wednesday, 20 January 2021 at 12:34:59 UTC+11 Robby Findler wrote:
>
> I'm no expert on algebras, but I think the way to work on this is not to
>> think "what Racket constructs are close that I might coopt to express what
>> I want?" but instead to think "what do I want my programs to look like" and
>> then design the language from there, reusing libraries as they seem helpful
>> or designing new ones that do what you want. Racket's
>> language-implementation facilities are pretty powerful (of course, if there
>> is nothing like what you end up needing, there will still be actual
>> programming to do ;).
>>
>
> Thanks Robby -- that's a very interesting way to look at library design
> that seems to make particular sense in the Racket environment.
>

An example of such an approach is racket-cas, a simple general purpose cas,
which
represents expressions as s-expression.

The polynomial 4x^2 + 3 is represented as '(+ 3 (* 4 (expt x 2)))
internally.

The expressions are manipulated through pattern matching. Instead of
using the standard `match`, I wanted my own version `math-match`.
The idea is that `math-match` introduces the following conventions in
patterns:

  prefix  x y z  will match symbols only
  prefix  r s will match numbers only (not bigfloats)
  prefix  p qwil match exact naturals only
  prefix 𝛼 𝛽 will match exact numbers
  prefix bool   will match booleans only

  suffix .0  will match inexact numbers only
  suffix .bf will match bigfloats only

As an example, here is the part that implements the symbolic natural
logarithm
(the assumption is that the argument u is in normalized form):

(define (Ln: u)
  (math-match u
[1  0] ; ln(1)=0
[r. #:when (%positive? r.)  (%ln r.)]  ; here %ln is an ln that
handles both reals and bigfloats
[@e  1]; @e is the syntax
matching Euler's e,  ln(e)=1
[(Complex a b) #:when (not (equal? 0 b))   ; all complex numbers
are handled here
   (⊕ (Ln (Sqrt (⊕ (Sqr a) (Sqr b
  (⊗ @i (Angle (Complex a b]
[(Expt @e v) v]; ln(e^v) = v
[(Expt u α) #:when (= (%numerator (abs α)) 1)  ; ln( u^(/n) ) = 1/n
ln(u)
(⊗ α (Ln: u))]
[(⊗ u v)  (⊕ (Ln: u) (Ln: v))] ; ln(u*v) = ln(u) + ln(v)
[_ `(ln ,u)])) ; keep as is

Note that the match pattern (⊗ u v) matches not only products of two
factors, but general products.
Matching (⊗ u v)  agains (* 2 x y z) will bind u to 2 and v to (* x y z).
This convention turned out to be very convenient.

I am happy about many aspects of racket-cas, but I wish I used structs to
represent the expressions.
Thanks to the custom matcher, it ought to be possible to change the
underlying representation
and still reuse most parts of the code. That's a future project.


Back to your project - what is the goal of the project?
Making something like GAP perhaps?
Do you want your users to supply types - or do you want to go a more
dynamic route?

/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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CABefVgwbdetq%2BWBa4h6MPLt1XxnhFQSiOACPC46xsx6cVA9imQ%40mail.gmail.com.


Re: [racket-users] Moving a Rust/Haskell abstract algebra library to Racket?

2021-01-24 Thread Jens Axel Søgaard
Den tor. 21. jan. 2021 kl. 05.06 skrev Stuart Hungerford <
stuart.hungerf...@gmail.com>:

> On Thursday, 21 January 2021 at 10:22:45 UTC+11 Jens Axel Søgaard wrote:
>


> > Back to your project - what is the goal of the project?
> > Making something like GAP perhaps?
> > Do you want your users to supply types - or do you want to go a more
> dynamic route?
>
> My project is really aimed at supporting self-directed learning of
> concepts from abstract algebra.
>
I was taught many years ago that to really understand something to try
> implementing it in a high level language.
>
That will soon expose any hidden assumptions or misunderstandings.
>

That's a very interesting project. You are so to speak optimizing for
readability.
I immediately get a vision of a SICM-like book, but for algebra instead of
classical mechanics.

Racket will be a good choice, since macros give you the possibility
of experimenting with suitable, easily understood syntax.

A tricky choice is to be made: how are the concepts going to be represented
as Racket values. Normal structs does not allow multiple inheritance.

Looking at a diagram such as the one below, raises the question whether the
relationship between the various concepts are to be modelled explicitly or
implicitly.

[image: image.png]

Maybe some kind of interface for each concept is needed?

/Jens Axel

Link to SICM in case you haven't seen it already.

https://mitpress.mit.edu/books/structure-and-interpretation-classical-mechanics

Note that the authors of SICM wrote a CAS in Scheme that is used in the
book.

-- 
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/CABefVgzzBkGYb7qPziPGoOGpDZ9QbpO%3DJVyDRrV_DLx5JJFA-w%40mail.gmail.com.


Re: [racket-users] Moving a Rust/Haskell abstract algebra library to Racket?

2021-01-30 Thread Jens Axel Søgaard
Den tor. 21. jan. 2021 kl. 05.06 skrev Stuart Hungerford <
stuart.hungerf...@gmail.com>:

> My project is really aimed at supporting self-directed learning of
> concepts from abstract algebra.
>
I was taught many years ago that to really understand something to try
> implementing it in a high level language.
>
That will soon expose any hidden assumptions or misunderstandings.
>
> An early attempt (in Rust) is at:
> https://gitlab.com/ornamentist/un-algebra
>
> By using the Rust trait system (and later Haskell typeclasses) I could
> create structure traits/typeclasses that don't clash with the builtin
> numeric types or with the larger more production oriented libraries in
> those languages in the same general area of math.
>
> Once I added generative testing of the structure axioms I could experiment
> with, e.g. finite fields and ensure all the relevant axioms and laws were
> (at least probabilistically) met.
>

Not knowing Rust nor traits, I have amused myself writing a very simple
version of traits.


#lang racket
(require (for-syntax syntax/parse racket/syntax))

;;;
;;; TRAITS
;;;

; This file contains a minimal implementation of traits.
; Overview:

;(define-trait trait (method ...)
;A trait is defined as list of methods names.

;(implementation trait structure body ...)
;An implementation of a trait for a given structure types,
;associates functions to each of the methods suitable
;for that structure type.
;Within body, the method names can be used.

;(with ([id trait structure expression] ...) . body)
;Similar to (let ([id expression] ...) . body),
;but within the body, one can use id.method
;to call a method.

; Expansion time helpers
(begin-for-syntax
  ; These functions produce new identifiers. The context is taken from stx.
  (define (identifier:structure-method stx s m)
(format-id stx "~a-~a" s m))
  (define (identifier:id.method stx id m)
(format-id #'stx "~a.~a" id m))

; get-methods : identifier -> list-of-identifiers
  (define (get-methods trait)
(syntax-local-value (format-id trait "~a-methods" trait


; SYNTAX  (define-trait Name (name ...))
;   This declares a new trait with the name Name having the methods name


(define-syntax (define-trait stx)
  (syntax-parse stx
[(_define-trait Name (id ...))
   (with-syntax ([trait-methods (format-id #'Name "~a-methods" #'Name)])
 (syntax/loc stx
   (define-syntax trait-methods (list #'id ...]

[(_define-trait Name (super-trait ...) (id ...))
 (displayln (list 'dt stx))
 (define ids(syntax->list #'(id ...)))
 (define supers (syntax->list #'(super-trait ...)))
 (with-syntax ([trait-methods(format-id #'Name "~a-methods"
#'Name)]
   [((super-method ...) ...) (map get-methods supers)])
   (syntax/loc stx
 (define-syntax trait-methods
   (list #'id ...
 #'super-method ... ...]))



; SYNTAX  (implementation trait structure . body)
;   Defines structure-method for each method of the trait.
;   The structure-method  is bound to  method.
;   If method is defined in body, then that binding is used.
;   If method is not bound in body, but bound outside, the outside binding
is used.
;   If method is not bound at all, an error is signaled.
(define-syntax (implementation stx)
  (syntax-parse stx
[(_implementation trait structure body ...)
 (define methods (get-methods #'trait))
 (with-syntax*
   ([(method ...); These short names are used
by the user
 (for/list ([method methods])
   (syntax-local-introduce
(format-id #'stx "~a" method)))]

[(structure-method ...)   ; Used in the output of the
`with` form.
 (for/list ([method methods])
   (identifier:structure-method #'trait #'structure method))])

   (syntax/loc stx
 (define-values (structure-method ...)
   (let ()
 body ...
 (values method ...)]))

(define-syntax (with stx)
  (syntax-parse stx
[(_with ([id trait structure expression] ...) . body)
 (define traits (syntax->list #'(trait ...)))
 (define ids(syntax->list #'(id ...)))
 (define structures (syntax->list #'(structure ...)))
 (define methodss   (map get-methods traits))

 (define (map-methods f id t s ms)
   (for/list ([m ms])
 (f id t s m)))

 (define (map-clauses f)
   (for/list ([id ids] [t traits] [s structures] [ms methodss])
 (map-methods f id t s ms)))

 (with-syntax
   ([((id.method ...) ...); names used inside `with`
 (map-clauses (λ (id t s m)
(syntax-local-introduce
 (identifier:id.method #'stx id m]

[((structure-method ...) ...) ; names used outside `with`
 (map-clauses (λ (id t s m)
  

Re: [racket-users] New to Racket

2021-02-18 Thread Jens Axel Søgaard
Den tor. 18. feb. 2021 kl. 08.09 skrev Rohan Posthumus <
rohanposthu...@gmail.com>:

> I am a data analyst and uses a lot of data science packages in Python.
> In order to learn Racket, I want to translate some of these into Racket. I
> need some help with where to start.
>
>- I finished "Beautiful Racket" and wonder whether I should make a
>data science DSL?
>- I read up a bit on Typed Racket and this seems like another option.
>The dynamic type checking seems to give overhead?
>- Translate some of these into Racket with classes and objects
>(similar to Python).
>
> Any advice?
>

I would start with plain Racket to begin with. It's simpler, and you can
switch to Typed Racket
a module at a time at a later date if you find the need.

Just in case you haven't found them already, if you need matrices over real
floating points,
take a look at:

https://docs.racket-lang.org/manual-flomat/index.html

/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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CABefVgyg_oYpzsb%3DosE0ADNmbrKEhEt3o%2BVbudAhWDeLv5OQww%40mail.gmail.com.


Re: [racket-users] flomat -- possible typo in documentation

2021-02-23 Thread Jens Axel Søgaard
Den tir. 23. feb. 2021 kl. 14.39 skrev Hendrik Boom :

> On
> https://docs.racket-lang.org/manual-flomat/index.html#%28part._.Matrix_.Creation%29
>
> it says
>
> > (sub! A i j m n)
> > Same as sub, but the elements are copied - the underlying array of
> flonums are shared.
>
> Presumably it should say "are not copied".
>

Thanks! The docs are now fixed.

/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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CABefVgxJL3MCOWLLVQQ2Wem5i1O6gKUMw1M91wEs5baBkLaA%2Bg%40mail.gmail.com.


Re: [racket-users] Bit Scan Reverse in Racket

2021-02-25 Thread Jens Axel Søgaard
Try integer-length.

https://docs.racket-lang.org/reference/generic-numbers.html?q=integer-length#%28def._%28%28quote._~23~25kernel%29._integer-length%29%29

I don't know how it is implemented.

/Jens Axel

Den tor. 25. feb. 2021 kl. 09.52 skrev Dominik Pantůček <
dominik.pantu...@trustica.cz>:

> Hello Racketeers,
>
> I'm slightly stuck with speeding up some calculations and the reason is
> that I need to compute the index of highest set bit in a number. So for
> 1 it is 0, for 2 it is 1, for 8 3, 1023 9 and 1024 10 ...
>
> The fastest Racket code I can come up with is as follows:
>
> (begin-encourage-inline
>   (define (highest-bit num)
> (let loop ((num num)
>(bit 0))
>   (if (unsafe-fx> num 0)
>   (loop (unsafe-fxrshift num 1)
> (unsafe-fx+ bit 1))
>   bit
>
> (Yes, it returns incorrect result for 0, but that must be checked
> elsewhere as the result cannot be defined for 0 anyway).
>
> However this is a single instruction operation on x86 (bsr) or two
> instruction operation (rbit and clz if I am not mistaken) on ARM. Dunno
> about PPC yet.
>
> I looked at CS internals a bit and although there is a "name collision"
> as the bsr mnemonics is used for ret (branch subroutine return?), it
> should be fairly easy to add something like fxbsr (-> fixnum? fixnum?)
> to Racket core.
>
> I also experimented with x64asm package but the results were even worse
> than the aforementioned tight loop (there is a lot of overhead in
> define-λ! generated functions).
>
> As the routine is typically called 40k-60k times per frame in my code
> (real-time rendering) it could really make a difference.
>
> Should I try to add it? How should it be named? What about BC?
>
> And more generic question - aren't there more similar operations that
> can be implemented efficiently on all supported CPUs that might be
> useful in general? Yes, I am aiming at SIMD as many of you know :)
> Especially with the expanded number of available FP registers to 8 on
> 64-bit x86 CS there surely is quite some potential to it.
>
>
> Cheers,
> Dominik
>
> --
> 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/a2a4fe83-877d-d7ed-4812-bd628c128659%40trustica.cz
> .
>


-- 
-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CABefVgwvxcsy1EN_W04fYUfp%2BGm2nbBdoeTEnD3UbKfCHcHyKw%40mail.gmail.com.


Re: [racket-users] SRFI 216 "SICP Prerequisites" vs #lang sicp

2021-03-09 Thread Jens Axel Søgaard
Den tir. 9. mar. 2021 kl. 20.38 skrev Tim Lee :

> I noticed that SRFI 216 "SICP Prerequisites" reached "final" status in
> January 2021. How will this affect #lang sicp? What are the differences
> between these two SICP aids?
>
> SRFI 216 link: https://srfi.schemers.org/srfi-216/srfi-216.html
> #lang sicp link:
> https://docs.racket-lang.org/sicp-manual/SICP_Language.html


The goal in each case is to provide an easy way to try the examples in the
book.

The documentation of `#lang sicp` is here:
https://docs.racket-lang.org/sicp-manual/SICP_Language.html

The code is here:
https://github.com/sicp-lang/sicp/blob/master/sicp/main.rkt

Note that  `sicp-pict` provides a modern implementation of the Henderson
picture language.
With colors and high resolution as well as support for pens and brushes.

https://github.com/sicp-lang/sicp/blob/master/sicp-pict/main.rkt

/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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CABefVgwKcjNCySFdZDvJ-xaD%3D2b4491NPjp6vkQ07WUnFmTobg%40mail.gmail.com.


Re: [racket-users] macros in Racket repository

2021-05-09 Thread Jens Axel Søgaard
Hi Tim,

In this case Ryan's method leads to:

https://github.com/racket/racket/blob/master/racket/collects/racket/private/qq-and-or.rkt#L440

But in case you are wondering about the style used in that file:
at the point where "qq-and-or.rkt" is used, none of the usual
syntax tools (such as syntax-case and syntax-parse) are available,
so it is written using only primitive constructs.

That is, that particular file does not represent the usual style of macro
writing.

/Jens Axel


Den søn. 9. maj 2021 kl. 16.13 skrev Ryan Culpepper :

> Here are the three most convenient ways I know of to find that information
> (which is "$RACKET/collects/racket/private/qq-and-or.rkt" in this specific
> case):
>
> If you use DrRacket, then open a file that uses `and`, right-click on an
> occurrence of `and`, and choose "Open Defining File" (which changes to
> "Jump to Definition (in Other File)" once DrRacket opens the file.
>
> If you use Emacs with racket-mode, go to an occurrence of `and` and hit
> "M-." (that is, hold down Meta/Alt and press the period key). You can also
> use "M-x racket-visit-definition". That opens the defining module and jumps
> to the definition.
>
> If you have the `whereis` package installed, run the command `raco whereis
> -b racket/base and` and it will print the path of the defining file.
>
> Ryan
>
>
> On Sun, May 9, 2021 at 3:26 PM Tim Meehan  wrote:
>
>> Where in the repository are macros like "and" and "or" defined?
>> I tried searching for "and" and "or" ... but you probably know how that
>> worked out.
>>
>> Thanks folks!
>>
>> --
>> 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/CACgrOxK6S8EOAGk_rPbE%2B_wMLJiSbpwMhVd4AeRL8C9%2BDW3mgg%40mail.gmail.com
>> <https://groups.google.com/d/msgid/racket-users/CACgrOxK6S8EOAGk_rPbE%2B_wMLJiSbpwMhVd4AeRL8C9%2BDW3mgg%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>>
> --
> 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/CANy33q%3DsLEH-ooUJxTay6pG1GNcRLZDUotNJ23L1HRTC1XqHwA%40mail.gmail.com
> <https://groups.google.com/d/msgid/racket-users/CANy33q%3DsLEH-ooUJxTay6pG1GNcRLZDUotNJ23L1HRTC1XqHwA%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>


-- 
-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CABefVgzgqRPzx6ct6LrN-TAfE18vsdqnopun0B63LmqqKxerAQ%40mail.gmail.com.


Re: [racket-users] Is there a good Racket DSL alternative to Image Magick?

2021-05-11 Thread Jens Axel Søgaard
Hi Robert,

There are some bindings for Magick in the example folder for the FFI
library.

https://github.com/racket/racket/tree/master/pkgs/racket-doc/ffi/examples

The bindings are in magic.rkt and examples of use are in use-magick.rkt
(see the bottom).

/Jens Axel


Den tir. 11. maj 2021 kl. 22.15 skrev 'John Clements' via Racket Users <
racket-users@googlegroups.com>:

> Racket has the ability to read a variety of different image files. I would
> go first to 2htdp/image’s “bitmap/file” to read images. “save-image” can
> write images (but only as png files). I believe there are also an array of
> lower-level image manipulation functions that are likely to have a less
> friendly interface :).
>
> Apologies in advance for any misleading information I might be providing….
>
> John
>
> > On May 11, 2021, at 1:09 PM, Robert Haisfield <
> roberthhaisfi...@gmail.com> wrote:
> >
> > Alternatively, does the normal images function for Racket work? When I
> was looking through the documentation I saw a lot about creating shapes but
> not about using image files.
> >
> > On Tuesday, May 11, 2021 at 2:03:33 PM UTC-6 Robert Haisfield wrote:
> > Hmm does the video language work for image files? If so, then I think it
> might work.
> >
> > On Tuesday, May 11, 2021 at 9:03:35 AM UTC-6 Sage Gerard wrote:
> > I hope that has what Robert is looking for, but I don't recognize that
> speech. In fact, I have a false memory, because I'm not finding the speech
> I'm looking for on https://con.racket-lang.org/2018/#speakers
> >
> > On 5/11/21 10:19 AM, Bruce O'Neel wrote:
> >> This might be it.
> >>
> >> (seventh RacketCon): Leif Andersen -- Movies as Programs: The Story of
> a Racket - YouTube
> >>
> >>
> >>
> >>
> >>
> >> 11 May 2021 15:30 Sage Gerard  wrote:
> >> I don't know of one off hand, but I believe RacketCon 2018 (?) included
> a presenter that showed a PostScript-like DSL for designers and artists.
> If pict not cover your needs, maybe dig into the presentations?
> >>
> >> Failing that, can you show what you'd hope the syntax would look like?
> That would probably help point you in the right direction,
> >>
> >> On 5/11/21 9:26 AM, Robert Haisfield wrote:
> >>> I have to do a bunch of .jpg and .png image resizings and was looking
> for a programmatic way to do it. Is their a Racket DSL for 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...@googlegroups.com.
> >>> To view this discussion on the web visit
> https://groups.google.com/d/msgid/racket-users/0d576c32-7d4d-4944-9cbc-c12f04406fccn%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...@googlegroups.com.
> >> To view this discussion on the web visit
> https://groups.google.com/d/msgid/racket-users/6e3aacdc-015b-2484-3bee-0c08e3fb612d%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...@googlegroups.com.
> >> To view this discussion on the web visit
> https://groups.google.com/d/msgid/racket-users/1620742795-01b81de5d6862fd390ec60605ee3bc9d%40pckswarms.ch
> .
> > --
> > ~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/b6a89a78-c92c-41c1-960a-49d64d8a5366n%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/404c8fad-befc-4b01-8728-48ce9b912117%40mtasv.net
> .
>


-- 
-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CABefVgwcGg867z5aEcSL2ub9sVci%3D08UtvNk%2BgRnGX_5WZd9mQ%40mail.gmail.com.


Re: [racket-users] canvas% mouse event handling difference in Racket CS?

2021-05-22 Thread Jens Axel Søgaard
Den lør. 22. maj 2021 kl. 05.37 skrev schle...@gmail.com <
schleesi...@gmail.com>:

> I have a racket gui app that uses a canvas% with overridden on-event and
> on-paint methods.
> When the user hovers over drawn elements the on-paint is called via (send
> this refresh)
> to display the element under the cursor with a selection/outline.
>
> Recently I noticed that this has gotten extremely slow.
> It seems to me this might be a difference between BC and CS, but I haven't
> checked with different versions in depth yet. (just from the
> behavior/performance I remember it had in the past)
>
> In the past a call to (send this refresh) seemed to be processed
> concurrently in regard to on-event.
> Now it seems like the first (send this refresh) eagerly triggers the
> on-paint and this on-paint somehow blocks the processing of on-event until
> the on-paint is finished, after that 1 more mouse event is processed
> re-triggering the on-paint.
> Effectively redrawing for every mouse event, causing the app to draw old
> uninteresting frames (because the mouse events aren't processed fast enough
> and only the last position is interesting for me).
>

I was looking at the code for racket/draw and spotted this:

;; The Racket BC can handle concurrent callbacks in different Racket
;; threads, because it copies the C stack in and out to implement
;; threads. The Racket CS cannot do that, so callbacks have to be
;; atomic. At the same time, we need some atomic callbacks to be able
;; to escape with an exception.

It matches your observations.

https://github.com/racket/draw/blob/master/draw-lib/racket/draw/unsafe/callback.rkt

/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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CABefVgwx9gkphjpGeA08Z-%3DdRvTZMfEbm1B%2B6HzPmi_fWiSKgw%40mail.gmail.com.


Re: [racket-users] Can we provide a list of functions?

2021-06-17 Thread Jens Axel Søgaard
Den tor. 17. jun. 2021 kl. 15.37 skrev Yossu Bonkers :

> I'm quite new to racket, so please pardon me if this is a dumb question.
>
> I'm working my way through the first tutorial in Beautiful Racket
> , and want to extend it.
> He only provides + and * as operators. I added support for others.
>
> The problem is that I need to specify the operators I support in two
> places, first where they are used in the handle function (see the
> highlighted line)...
>
> (define
> 
> (handle [arg #f])
>   (cond
> 
>[(number?
> 
> arg) (push-stack! arg)]
> *   [(or
> 
> (equal?
> 
> *
> 
> arg) (equal?
> 
> +
> 
> arg))*
>  (define
> 
> op-result (arg (pop-stack!) (pop-stack!)))
>  (push-stack! op-result)]))
>
> ..and then again when they are provided...
>
> (provide
> 
> +
> 
> *
> 
> )
>
> I was wondering if it would be possible to specify the supported operators
> in a list...
>
> (define my-funs '(f1 f2))
>
> ...which could be used in handle, and then provide the functions in the
> list.
>



>
> You can't simple do...
>
> (provide my-funs)
>
> ...as this is a list of symbols. Equally you can't iterate the list and
> call provide on each member, as provide has to be a top-level function.
>
> So, is there any way to provide the functions in the list?
>

I'll give you the big picture.

As you have observed, `provide` is a compile time construct and can't be
used at runtime (where the list my-funs lives).
Since `provide` lives at compile time, the only solution is to use macros.

Define a macro, say, define-binary-function that can used as:

   (define-binary-function *)
   (define-binary-function +)

Given that, one can always define a define-binary-functions, that can be
used as:

   (define-binary-functions + *)

and expands into multiple instances of define-binary-function.

Now, what must define-binary-function do?
It must:
   1) expands to a provide of the function name
   2) add the function name to a list that holds names (symbols) of all
binary functions.

You can accomplish 2) by having a global:

  (define all-binary-functions '())

and let define-binary-function expand to both a provide and to

  (set! all-binary-functions (cons 'id all-binary-functions))

where id is from the use (define-binary-function id).

In the definition of handle, you will then need to make use
of all-binary-functions.


If you are familiar with macros, I hope the overview will give you a good
start.
If not, the overview skipped a lot of details, so you will need to look at
an
introduction to macros first.

If you are interested, I'll be happy to send you a work-in-progress macro
tutorial
I am working. I am always looking for feedback to make it better.

/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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CABefVgycHfj0B_M8ks8V_MWG_idaOcCVHu5ZVTL_v3DjpT77xg%40mail.gmail.com.


Re: [racket-users] Is it possible to effectively display a window with a bitmap background?

2021-06-25 Thread Jens Axel Søgaard
Use canvas%

fre. 25. jun. 2021 kl. 18.10 skrev Don Green :

> Is it possible to effectively display a window with a bitmap background?
> In racket/gui, I can see how to apply a bitmap to a button.
> If the only way to display a bitmap is in a button, is it practical to
> size the button to the entire frame or pane in the frame?
>
>
> --
> 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/565f3573-8759-4d72-8277-35bf3297befdn%40googlegroups.com
> <https://groups.google.com/d/msgid/racket-users/565f3573-8759-4d72-8277-35bf3297befdn%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
-- 
-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CABefVgzJJGXEwoFaqFiUkRDpXEqakAYUd4qNwDce2KoAJVvpyQ%40mail.gmail.com.


Re: [racket-users] Speeding up the conversion of flvectors to string

2021-06-27 Thread Jens Axel Søgaard
As Bogdan writes, the problem is repeatedly calling `string-append`.
Instead one can make a list of all the small strings and then use
`string-join` at the end.

#lang racket
(require racket/flonum)

(define (xy->string x y)
  (string-append
   (~r x #:precision 1) ","
   (~r y #:precision 1)))

(define (xy-vectors->strings x-vec y-vec)
  (for/list ((x (in-flvector x-vec))
 (y (in-flvector y-vec)))
(xy->string x y)))

(define (xy-vectors->string x-vec y-vec)
  (string-join (xy-vectors->strings x-vec y-vec) " "))


Den søn. 27. jun. 2021 kl. 15.26 skrev Alessandro Motta :

> Hi racket-users!
>
> I've recently become interested in Lisp/Scheme and have started to hack
> in Racket. The excellent documentation, the fast integrated search, and
> DrRacket have made that a real pleasure.
>
> Thank you for that!
>
> I've been working on a tool to convert notes from the reMarkable 2
> tablet to SVG files. At the core is the conversion of (x, y) coordinate
> pairs from two `flvector`s to a string of the form "x1,y1 x2,y2 x3,y3".
>
> ```
> (define (xy->string x y)
>   (string-append
>(~r x #:precision 1) ","
>(~r y #:precision 1)))
>
> (define (xy-vectors->string x-vec y-vec)
>   (for/fold ((coordinates "")
>  (separator "")
>  #:result coordinates)
> ((x (in-flvector x-vec))
>  (y (in-flvector y-vec)))
> (values (string-append
>  coordinates
>  separator
>  (xy->string x y))
> " ")))
> ```
>
> This is currently the bottleneck for large conversion jobs.
>
> Profiling these functions with `profile-flame-graph` resulted in
>
> https://gist.githubusercontent.com/amotta/cfe4b19e24455af219521c9e94455c67/raw/dbbc87bd2f6dd4e27c33831749baa90fffdaed55/flvector-to-coordinates-string-flamegraph.svg
>
> The full profiling script is available at
> https://gist.github.com/amotta/e76197082bb1bf63538ede01872917f3
>
> Roughly 90% of time is spent in `contract/private/arrow-val-first.rkt`.
> Based on my very limited understanding of Racket, it seems that ~38% of
> time is spent handling keyword arguments (presumably `#:precision 1`?).
> The `catnp` function (the conversion from flonum to string, I think)
> takes up only ~11% of time.
>
> Is this interpretation of the flame graph correct? If so, are there any
> obvious blunders on my part? Any ideas for how to speed up this code?
>
>
> Best wishes,
> Alessandro
>
> --
> 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/0139e84f-be70-2bb8-14ac-0159915e7681%40gmail.com
> .
>


-- 
-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CABefVgwV%3DZ9We2ZHAFBP1yUdbpkSVP76LBBuU3%2Bdkysm4WYH_Q%40mail.gmail.com.


Re: [racket-users] Speeding up the conversion of flvectors to string

2021-06-27 Thread Jens Axel Søgaard
Den søn. 27. jun. 2021 kl. 18.58 skrev Alessandro Motta :

> I also like Jens' code for its pure functional elegance. I'm surprised
> that building up a long list of short strings before joining them is so
> much faster. After all, isn't the final `string-join` essentially doing
> what the original code snipped did? (Clearly not! I will have a look at
> the implementation.)
>

The following is the same answer as Robby's, but fills in some details.
I wrote this mainly because I couldn't find a web-page with the explanation.

Let's say we have two strings a and b of lengths m and n respectively.

How much work must  (string-append a b) do?

Conceptually the following steps need to be done:
  1. Allocate a new string c of length m+n.
  2. Copy the string a into c.
  3. Copy the string b into c.

This means that the time (work) needed to append the strings a and b are
proportional to m+n.

How much work is done here?

(string-append "x" (string-append "y" (string-append "z" "")))

First (string-append "z" "w") takes time 1+0=1 with the result "z".
Then (string-append "y" (string-append "z" "")) or  (string-append "y" "z")
takes time 1+1=2 with the result "yz".
Then (string-append "x" (string-append "y" (string-append "z" ""))) or
(string-append "x" "yz") takes time 1+2 = 3 with result "xyz".
In total we have used time 1+2+3 =6.

We see that if we 3 times use string-append to add strings of length 1,
then we use time 1+2+3=6.
In general, if we n times use string-append to add strings of length 1,
then we use time 1+2+3+...+n.
The last sum is more or less n^2.  See [1].

The same thing happens in your loop, where you repeatedly use string-append
to append a small string.
The length of the small string is no longer 1, but the same happens - and
the time used by the
loop is proportional to n^2.


Now suppose we have a list of the strings to append
(list "x" "y" "z")
and we need to append them. How much work is there now?

Well, first we can calculate the length of the result 1+1+1 = 3.
Then we allocate a new string of length 3. Then each individual
string is copied and that takes time 1+1+1=3.

Here, each string is only copied once. For comparison in the loop version
the string z is copied multiple times.


But wait - why does a loop that uses cons multiple times to build up
a list not have the same problem?

Because in (cons x xs) the existing list xs isn't copied.
The steps are
   1. a new pair with two cells  (the car and the cdr) are allocated
   2. the contents of the car is set to x
   3. the contents of the cdr is set to xs.

This always takes the same amount of time, no matter how long the list xs
is.
This means that the time used by cons is constant (that is, proportional to
1).

Note: This phenomenon that using string-append in a loop is not a Racket
only problem.
  It is a common pitfall in many languages.



[1] Remember the famous story of Gauss as a child that calculated
1+2+...1000 ?
 https://www.youtube.com/watch?v=Dd81F6-Ar_0


/Jens Axel  -  https://racket-stories.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/CABefVgzku_POA_673-bChPe1jyij_yQ9dH0Yuu6fR-VMAghwGg%40mail.gmail.com.


Re: [racket-users] frame width and (get-display-size) ...

2021-08-05 Thread Jens Axel Søgaard
Which OS?



Den tor. 5. aug. 2021 kl. 17.36 skrev Don Green :

> Creating a frame width that is half of the width given by
> (get-display-size), then moving the resulting window to the right and left
> of the screen you can see that if you had 2 windows of the same size they
> would not touch each other as you would expect.
> For some reason, dividing the total pixel width in HALF, DOES NOT give 2
> windows that will fill the space.
> ;Instead there is a mysterious gap that happens to be about the width of
> the O.S. vertical toolbar.
> Can anyone explain?
> 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.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/racket-users/1e605128-50b3-4578-bf60-2aaa68016006n%40googlegroups.com
> <https://groups.google.com/d/msgid/racket-users/1e605128-50b3-4578-bf60-2aaa68016006n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>


-- 
-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CABefVgw-AyTD_m1oo62rfUg1y2bSy0gCobjW58GU-rUKV%2BUX6w%40mail.gmail.com.


Re: [racket-users] problem of gui layout using side-by-side frames

2021-08-12 Thread Jens Axel Søgaard
Den tor. 12. aug. 2021 kl. 20.44 skrev George Neuner :

>
> If I understand correctly, Don seems to want menus in his side-by-side
> "panels".
>

Are we talking menu bar menus or contextual menus?

On macOS the menu bar menu belongs to the application and not a window.

https://developer.apple.com/design/human-interface-guidelines/macos/menus/menu-anatomy/

/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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CABefVgxCaZQB%3Dq_2cO1U8%3DGAFMmB16ii0-OVuFYxPv1HSQb4_g%40mail.gmail.com.


Re: [racket-users] Doc pages search engine difficulties

2021-08-17 Thread Jens Axel Søgaard
Den tir. 17. aug. 2021 kl. 16.34 skrev Dexter Lagan :

> Hello there,
>
>   I'm trying to teach one of my coworkers how to search for function names
> in the Racket manual, and I'm having serious problems finding very simple
> things, such as the function to display the file browser dialog (get-file).
> I know most function names by heart but my coworker isn't that fortunate. I
> see I'm not the only one, as per these
> 
> Stack Overflow answers.
>
>   Does anybody know why the search engine doesn't seem to index page
> contents other than exact function names and titles?
>
>   I understand search engines aren't trivial matters, but I'm thinking
> that finding very basic Racket functions would be crucial for beginners. If
> somebody could point me to the search engine repo, I'd love to have a look.
>

Full text search is possible to add - but it would require some changes to
the current setup.

One goal of the documentation system is that you can use the documentation
on your own computer without any internet access.
When you enter a search term, a piece of JavaScript runs directly on your
computer without any queries sent to a server.
In order for this to work there needs to be a prebuilt index in which the
search term an be looked up.
This index is built by `raco setup`. For each function/macro definition in
the documentation an entry is added to the index
with associated information (which module is defined in etc.).

If you use the search page at docs.racket-lang.org the index will be
downloaded to your computer first.
Currently the index (the file name is plt-index.js )  has a size around 12
MB.

If full text search is to be added the index would be considerably larger -
which means the index can no longer
be downloaded. The actual search then needs to take place on the
web-server.

Could a standard full text indexer be used? Maybe - but most likely it will
be necessary to build a custom one.
Standard indexers stem words ("apple" and "apples" are indexed as the same
word). They also filter out
punctuation such as  - . ? / etc. This in turn makes it difficult to search
for identifiers.

The compromise today is that we have precise search among the identifiers
and keywords marked as
imported by the documentation writers. If full text search is needed, then
Google is the place to look.

Back in the day before the current documentation search - it was possible
to make a custom Google
backed search page that only indexed a certain set of sites. It worked
"okay", but not great.
The current system works much better.

That said, I understand that the amount of documentation has grown to such
a size, that it can
be difficult for newcomers to navigate. Maybe "cheat sheets" such as

 https://docs.racket-lang.org/racket-cheat/index.html

could be added to some sections in order to give an overview of what's
available?

/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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CABefVgx8QVfVs9shP-OXBF9ojLNqAeLGCvpeHq0Z3i%2Be0k_vwg%40mail.gmail.com.


Re: [racket-users] How to discover a struct's interface without Dr Racket?

2021-10-31 Thread Jens Axel Søgaard
On Tuesday, October 26, 2021 at 5:02:46 PM UTC-7 bc.be...@gmail.com
>>>>> wrote:
>>>>> > I understand why structs are opaque, by default, but I want to
>>>>> discover the public interface of some struct type, that is, a list of the
>>>>> procedures defined by the struct.
>>>>> >
>>>>> > Here is an example. Suppose I want to find out all the procedures
>>>>> defined on an instance of the syntax struct
>>>>> >
>>>>> > #'42
>>>>> >
>>>>> > Dr. Racket shows an expander clicky that shows some formatted
>>>>> information inside the instance :
>>>>> >
>>>>> >
>>>>> >
>>>>> > Uncapitializing the names in the display reveals the interface:
>>>>> >
>>>>> > (syntax-position #'42) ~~> 790
>>>>> > (syntax-span #'42) ~~> 2
>>>>> > (syntax-original? #'42) ~~> #t
>>>>> >
>>>>> > etc.
>>>>> >
>>>>> > I want to discover those procedure names in my racket program, not
>>>>> manually by visually inspecting graphics in Dr Racket.
>>>>> >
>>>>> > I found this trick for structs that I define:
>>>>> >
>>>>> > #lang racket
>>>>> > (require (for-syntax racket/struct-info))
>>>>> > (require racket/pretty)
>>>>> >
>>>>> > (struct foo (a b))
>>>>> > (begin-for-syntax
>>>>> >   (displayln
>>>>> >(extract-struct-info
>>>>> > (syntax-local-value
>>>>> >  #'foo
>>>>> >
>>>>> > ~~>
>>>>> >
>>>>> >
>>>>> >
>>>>> > but it doesn't work for the syntax type
>>>>> >
>>>>> > (begin-for-syntax
>>>>> >   (displayln
>>>>> >(extract-struct-info
>>>>> > (syntax-local-value
>>>>> >  #'syntax
>>>>> >
>>>>> > ~~>
>>>>> >
>>>>> >
>>>>> >
>>>>> > I'd be grateful for advice and an example of how to get the
>>>>> interface of "syntax" without Dr Racket and without grovelling docs.
>>>>> >
>>>>> > --
>>>>> > 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/8e4ca03e-e276-4c42-a662-4fcf7c994387n%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/CAK2VK6tMxFH0oEq4iCgk7PW-4yJTB8xNr_b3F6GPwQS1MZVLwQ%40mail.gmail.com
>>>> <https://groups.google.com/d/msgid/racket-users/CAK2VK6tMxFH0oEq4iCgk7PW-4yJTB8xNr_b3F6GPwQS1MZVLwQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>>> .
>>>>
>>> --
>> 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/c1c4f0f3-9c8d-430d-8615-4ec2cbea90f4n%40googlegroups.com
>> <https://groups.google.com/d/msgid/racket-users/c1c4f0f3-9c8d-430d-8615-4ec2cbea90f4n%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
> --
> 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/CAAGM456vwtx80%3DX44UiLZAMjbL6O0zMHOZSyc32L6opM89Bjew%40mail.gmail.com
> <https://groups.google.com/d/msgid/racket-users/CAAGM456vwtx80%3DX44UiLZAMjbL6O0zMHOZSyc32L6opM89Bjew%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>


-- 
-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CABefVgwBi8-2cLuA7-dtiM%2BnbxN5ZriPLcG1JX3ATTw2xyQd8w%40mail.gmail.com.


Re: [racket-users] How to discover a struct's interface without Dr Racket?

2021-10-31 Thread Jens Axel Søgaard
A quick example:

#lang racket
(require racket/require)
(require (filtered-in (λ (name) (regexp-replace #rx"struct[+][+]" name
"struct"))
  struct-plus-plus))

(struct horse (breed color legs))

(define beauty (horse 'arabian 'black 4))

(define info (force (struct-ref beauty)))
(map struct-field-name (struct-info-fields info))

The result is:
'(breed color legs)

Den søn. 31. okt. 2021 kl. 13.06 skrev David Storrs :

>
>
> On Sun, Oct 31, 2021, 7:49 AM Jens Axel Søgaard 
> wrote:
>
>> Hi Brian,
>>
>> A few random thoughts:
>>
>> > I would like, given only the symbol foo referring to the struct type
>> itself,
>> > to discover (at least) the list of procedures foo?, foo-a, foo-b, plus
>> > anything else the author of foo (the type) wants me to see.
>>
>> When you want to look this up, is it in the repl (i.e. at runtime)?
>>
>> The standard `struct` construct doesn't store much reflection information.
>> Instead of fighting the standard construct, you can consider making a
>> little variation.
>>
>> If you are satisfied with having info for the structs defined in your own
>> program
>> (i.e. modules you have written yourself), then you can consider making a
>> module, say, `fancy-struct` that exports a macro where
>>
>>(fancy-struct yada ...)
>>
>> expands into
>>
>>(begin
>>   (fancy-struct yada ...)
>>   )
>>
>> Using `rename-out` you can export it as `struct`, so it can be used
>> without changing any existing code.
>>
>> /Jens Axel
>>
>
> Coincidentally, that module exists!
>
>
> https://docs.racket-lang.org/struct-plus-plus/index.html#%28part._.Reflection%29
>
>
>
>>
>>
>> Den søn. 31. okt. 2021 kl. 11.42 skrev Matt Jadud :
>>
>>> Hi Brian,
>>>
>>> Does this help move you forward?
>>>
>>> It has been a while since I've stared at macros in Racket, so this might
>>> be easier...
>>>
>>> Also, make sure you're executing this code in a module. If you're
>>> working in a REPL, I suspect all bets are off. It is certainly the case
>>> that you could combine several of my exploration steps into a
>>> simpler/cleaner macro, instead of generating lists of symbols, converting
>>> them back to syntax objects, and so on.
>>>
>>> Also, as a solution/exploration, I... don't know how this would interact
>>> with the full range of possible structs. Someone who knows more about
>>> syntax and structs should be able to speak to how you'd find out all of the
>>> defined functions that spawn from struct definition/creation. (It might
>>> also be useful to know *why* you want to destructure structs this way?
>>> Knowing that may illuminate some other path forward.)
>>>
>>> #lang racket
>>> (require racket/struct-info)
>>>
>>> (struct A (b c))
>>>
>>> (struct B (e f) #:transparent)
>>>
>>> (require (for-syntax racket/struct-info))
>>> (define-syntax (get-field-names stx)
>>>   (syntax-case stx ()
>>> [(_ sym)
>>>  #`(quote
>>> #,(struct-field-info-list
>>>(syntax-local-value #'sym)))
>>>   ]))
>>>
>>> ;; These let me see the field names
>>> (get-field-names A)
>>> ;; Returns '(c b)
>>> (get-field-names B)
>>> ;; Returns '(f e)
>>>
>>> ;;
>>> https://stackoverflow.com/questions/20076868/how-to-know-whether-a-racket-variable-is-defined-or-not
>>> (define-syntax (defined? stx)
>>>   (syntax-case stx ()
>>> [(_ id)
>>>  (with-syntax ([v (identifier-binding #'id)])
>>>#''v)]))
>>>
>>> (define-syntax (proc-names stx)
>>>   (syntax-case stx ()
>>> [(_ sym)
>>>  (let ([names (map (λ (s)
>>>  (string->symbol
>>>   (format "~a-~a" (syntax-e #'sym) s)))
>>>(struct-field-info-list
>>> (syntax-local-value #'sym))
>>>)])
>>>#`(quote #,names))]))
>>>
>>> ;; This...
>>> (proc-names A)
>>> ;; Returns '(A-c A-b)
>>>
>>> (define-syntax (names-exist? stx)
>>>   (syntax-case stx ()
>>> [(_ sym)
>>>  (let ([names (map

Re: the end of the [racket-users] mailing list and the migration to Discourse as a forum for Racket

2021-11-22 Thread Jens Axel Søgaard
There are no plans of closing the mailing list.

Things take time.

Different forums for communication have different strengths.
Discourse might attract an audience that is unfamiliar to mailing lists.
There is no need to rush things however.
In due course maybe the number of users on the forum will
grow to outshadow the number of participants on the mailing list,
but it will take some years.

/Søgaard


“Put up in a place
where it is easy to see
the cryptic admonishment
T.T.T

When you feel how depressingly
slowly you climb
it's well to remember that
Things Take Time.”- Piet Hein




Den man. 22. nov. 2021 kl. 14.06 skrev Etan Wexler :

> The stewards of Racket <https://racket-lang.org/> have decided that it’s
> time to give up on the mailing list (that is, racket-users
> <https://groups.google.com/group/racket-users>, to which this message is
> a contribution). The stewards of Racket <https://racket-lang.org/> have
> designated another forum for Racket <https://racket.discourse.group/> as
> the successor to racket-users
> <https://groups.google.com/group/racket-users>. This other forum for
> discussing Racket <https://racket.discourse.group/> has as its basis the
> software named “Discourse” <https://www.discourse.org/>, which is
> open‐source. Enlisting is prerequisite to contributing to the Discursive
> forum for Racket <https://racket.discourse.group/>. Enlisting is
> prerequisite to receiving as Internet mail the contributions to the
> Discursive forum for Racket <https://racket.discourse.group/>. The
> stewards of Racket <https://racket-lang.org/> have published a facility
> for enlisting as a participant in the Discursive forum for Racket
> <https://racket.discourse.group/invites/okLTSrQw1T>.
>


-- 
-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CABefVgzDEEB_hiaznjnpKMr860mTpah8%3DmUda5bLFe48mpNmhA%40mail.gmail.com.


Re: [racket-users] Beginner's question

2021-12-14 Thread Jens Axel Søgaard
Try reversing the order for arguments for both fp and f.

/Jens Axel

Den tir. 14. dec. 2021 kl. 19.48 skrev Cyrille DEUSS <
cyrille.de...@gmail.com>:

> #lang racket
> (require racket/format)
>
> (define pp_number
>   (lambda (n)
>  (~a n #:width 6 #:align 'right  #:left-pad-string "0")))
>
> (define fp
>   (lambda (s n)
> (string-append (pp_number n) " + " s)))
>
> (define f
>   (lambda (s n)
> (format "~a + ~a" n s)))
>
> (foldl f "" '(1 2 3))
> ; works great !
>
> (foldl fp "" '(1 2 3))
> ; and why not this one ?
>
> Thanks in advance.
> Cyrille
>
> --
> 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/e72b954e-0b48-4830-b253-34b904d726bcn%40googlegroups.com
> <https://groups.google.com/d/msgid/racket-users/e72b954e-0b48-4830-b253-34b904d726bcn%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>


-- 
-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CABefVgxN5%2B%2BSxfLganjeVB%3DpwuRXUEBEsbofoLh5asmcZ%2BWpBQ%40mail.gmail.com.


Re: [racket-users] can't open DrRacket 8.5 on M1 macOS

2022-07-04 Thread Jens Axel Søgaard
Can you open it from the terminal:

open /Applications/Racket\ v8.5/DrRacket.app

This way any errors will be visible.

/Jens Axel

Den man. 4. jul. 2022 kl. 12.49 skrev Kuang-Chen Lu :

> Hi,
>
> My colleague can’t open a fresh installation of DrRacket. She installed
> the DrRacket 8.5 Apple Silicon 64-bit version.
>
> Her screen recording
> <https://drive.google.com/file/d/1w5jvtq7QK5iAcVAjZA3VRw9z8a9H_fnz/view?usp=sharing>
> shows more details:
>
>- After trying to open DrRacket (00:00 of the video), no window shows
>up
>- Besides, DrRacket cannot be found in the Activity Monitor (00:08),
>which confirms that DrRacket is not running.
>- After trying to open DrRacket again (00:15), still, no window shows
>up
>- If you look at the Dock (the sequence of App icons at the bottom of
>the screen) carefully, you will notice that something shows up and then
>disappears immediately every time (00:02 and 00:16) DrRacket is opened.
>This suggests that DrRacket is closed immediately after being opened.
>
> Thanks,
> Kuang-Chen
>
> --
> 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/3ec173be-bfbd-4ba2-a019-12b4479501c9n%40googlegroups.com
> <https://groups.google.com/d/msgid/racket-users/3ec173be-bfbd-4ba2-a019-12b4479501c9n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>


-- 
-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CABefVgxtHy_bFApgtts-Azbr09jBFLvVszuw06Ui_MoZKuPD%2BQ%40mail.gmail.com.


Re: [racket-users] can't open DrRacket 8.5 on M1 macOS

2022-07-04 Thread Jens Axel Søgaard
Also - was Racket moved to the Applications ?
It looks like your colleague is opening from the downloaded archive [but I
could be wrong].

Den man. 4. jul. 2022 kl. 13.18 skrev Jens Axel Søgaard <
jensa...@soegaard.net>:

> Can you open it from the terminal:
>
> open /Applications/Racket\ v8.5/DrRacket.app
>
> This way any errors will be visible.
>
> /Jens Axel
>
> Den man. 4. jul. 2022 kl. 12.49 skrev Kuang-Chen Lu <
> kuang-chen...@brown.edu>:
>
>> Hi,
>>
>> My colleague can’t open a fresh installation of DrRacket. She installed
>> the DrRacket 8.5 Apple Silicon 64-bit version.
>>
>> Her screen recording
>> <https://drive.google.com/file/d/1w5jvtq7QK5iAcVAjZA3VRw9z8a9H_fnz/view?usp=sharing>
>> shows more details:
>>
>>- After trying to open DrRacket (00:00 of the video), no window shows
>>up
>>- Besides, DrRacket cannot be found in the Activity Monitor (00:08),
>>which confirms that DrRacket is not running.
>>- After trying to open DrRacket again (00:15), still, no window shows
>>up
>>- If you look at the Dock (the sequence of App icons at the bottom of
>>the screen) carefully, you will notice that something shows up and then
>>disappears immediately every time (00:02 and 00:16) DrRacket is opened.
>>This suggests that DrRacket is closed immediately after being opened.
>>
>> Thanks,
>> Kuang-Chen
>>
>> --
>> 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/3ec173be-bfbd-4ba2-a019-12b4479501c9n%40googlegroups.com
>> <https://groups.google.com/d/msgid/racket-users/3ec173be-bfbd-4ba2-a019-12b4479501c9n%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>
>
> --
> --
> Jens Axel Søgaard
>
>

-- 
-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CABefVgyA1XMVDfm4ZjgzcV%3DDEfPJQzd_9-wzyuGoCUXE2%3D%3DqyA%40mail.gmail.com.


Re: [racket-users] Some DrRacket preferences unreadable

2022-12-29 Thread Jens Axel Søgaard
This looks odd indeed.

Does it help to:
  1. Change the font DrRacket uses
  2. Restart DrRacket


Den tor. 29. dec. 2022 kl. 13.54 skrev AvW :

> Hi,
>
> after having installed Racket 8.7 (Windows 64 bit) I cannot read 3 tabs of
> the preferences window; the other tabs appear to be OK.
>
> See attachments.
>
> Some relevant data:
> - Windows 11 Pro 22H2 build 22621.963
> - Racket installation: racket-8.7-x86_64-win32-cs.exe
>
> Any ideas?
>
> TIA,
>Arie
>
> --
> 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/beaa2ef6-afd2-4686-829a-390eb69f5620n%40googlegroups.com
> .
>
> Beyond the Racket Users Google Group, Racket Discussions take place on
> Discourse ( https://racket.discourse.group/ ) and Discord (
> https://discord.gg/6Zq8sH5 ). Discussion (but less active) also takes
> place on the Racket Slack https://racket.slack.com/ ( sign up at
> https://racket-slack.herokuapp.com/ ), and IRC #racket
> https://kiwiirc.com/nextclient/irc.libera.chat/#racket
> ---
> 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/4ba70e7b-e7ac-4720-898a-d9548dbc8426n%40googlegroups.com
> <https://groups.google.com/d/msgid/racket-users/4ba70e7b-e7ac-4720-898a-d9548dbc8426n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>


-- 
-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/beaa2ef6-afd2-4686-829a-390eb69f5620n%40googlegroups.com.

Beyond the Racket Users Google Group, Racket Discussions take place on 
Discourse ( https://racket.discourse.group/ ) and Discord ( 
https://discord.gg/6Zq8sH5 ). Discussion (but less active) also takes place on 
the Racket Slack https://racket.slack.com/ ( sign up at 
https://racket-slack.herokuapp.com/ ), and IRC #racket 
https://kiwiirc.com/nextclient/irc.libera.chat/#racket
--- 
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/CABefVgyCS3Wg4Sh2vTy3d7gQJeUTNbzpzqRkMSH1DEjVwPQnhg%40mail.gmail.com.


Re: [racket-users] Macro generating macro question

2023-05-24 Thread Jens Axel Søgaard
Hi Kevin,

When you are writing macro generating macros there are two levels of
ellipsis.
The outer one, which you can write as ... as normal and the inner one which
you need to escape.
You can escape it with (... ...). That looks odd to me, so I usually bind
it to an identifier named ooo.

#lang racket
(require (for-syntax syntax/parse
 racket/syntax))

(define-syntax (make-id-macro stx)
  (syntax-parse stx
[(_ id)
 (with-syntax ([name (format-id #'id "do-~a" #'id)]
   [ooo  #'(... ...)])
   #'(define-syntax (name stx)
   (syntax-parse stx
 [(_ parms ooo)
  #'(list parms ooo)])))]))

(make-id-macro foo)
(do-foo 1 2)


See you on Racket Discourse.
/Jens Axel


Den ons. 24. maj 2023 kl. 06.27 skrev Kevin Forchione :

> Hi guys,
> I’m stumped.  In a nutshell I want to write a macro that is passed  an id
> and will produce a macro called id that can take variable arguments. I’m
> sure I’m overlooking something fundamental. The basic form below “works” if
> I don’t have ellipsis aver the variables, but that’s not what I’m after.
> Here’s an example that is obviously wrong, but is along the lines of what
> I’m looking for:
>
> #lang racket
>
>
> (require (for-syntax syntax/parse
>  racket/syntax))
>
> (define-syntax (make-id-macro stx)
>   (syntax-parse stx
> [(_ id)
>  (with-syntax ([name (format-id #'id "do-~a" #'id)])
>#'(define-syntax (name stx)
>(syntax-parse stx
>  [(_ parms ...)
>   #'( list parms ...)])))]))
>
> Any help in this and explaining why it fails would be greatly appreciated.
>
> -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.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/racket-users/beaa2ef6-afd2-4686-829a-390eb69f5620n%40googlegroups.com
> .
>
> Beyond the Racket Users Google Group, Racket Discussions take place on
> Discourse ( https://racket.discourse.group/ ) and Discord (
> https://discord.gg/6Zq8sH5 ). Discussion (but less active) also takes
> place on the Racket Slack https://racket.slack.com/ ( sign up at
> https://racket-slack.herokuapp.com/ ), and IRC #racket
> https://kiwiirc.com/nextclient/irc.libera.chat/#racket
> ---
> 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/6BC84910-3AC4-4729-8BAA-D1488E84A54B%40gmail.com
> .
>


-- 
-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/beaa2ef6-afd2-4686-829a-390eb69f5620n%40googlegroups.com.

Beyond the Racket Users Google Group, Racket Discussions take place on 
Discourse ( https://racket.discourse.group/ ) and Discord ( 
https://discord.gg/6Zq8sH5 ). Discussion (but less active) also takes place on 
the Racket Slack https://racket.slack.com/ ( sign up at 
https://racket-slack.herokuapp.com/ ), and IRC #racket 
https://kiwiirc.com/nextclient/irc.libera.chat/#racket
--- 
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/CABefVgxroAUQhxD6sGaAbL%2B_2WwLAzMdRa_8o_%3DBFx%3DByXS9yw%40mail.gmail.com.


Re: [racket-users] How 'Pythonic' Can Racket Be Made?

2023-10-12 Thread Jens Axel Søgaard
Den man. 9. okt. 2023 kl. 19.35 skrev Adam Golding :

> I am going to write a language called 'micronatrix' that is pythonic in
> its use of whitespace and even with python 2 type print statements but very
> minimal and pared down -- has similar ground been trodden?
>

There a #lang python implementation here:

https://github.com/pedropramos/PyonR/tree/master

A paper on it:

https://www.inesc-id.pt/ficheiros/publicacoes/10173.pdf

/Jens Axel

-- 
This group is deprecated and retained as an archive. 

Racket discussions have moved to the Racket Discourse at  
https://racket.discourse.group/ .

---
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.
--- 
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/CABefVgxnySZVEK5vAm-goZ3VJN69CG0gZe%2BVc0TiNVWst_%3DS2Q%40mail.gmail.com.


Re: [racket] recent updates to Whalesong development: web-world

2011-09-05 Thread Jens Axel Søgaard
Works on the iOS simulator version 4.3 (All three devices: iPad, iPhone,
and, iPhone (retina)).

/Jens Axel


2011/9/5 Danny Yoo 

> On Fri, Sep 2, 2011 at 4:33 PM, Danny Yoo  wrote:
> > We're smack in the middle of implementing web-world for Whalesong,
> > which is analogous to regular world, but with web pages.  Unlike
> > regular world, the callbacks in web-world take in both the world as
> > well as a functional representation of the DOM.
>
> Request for browser help.  I'm trying to make the Whalesong-compiled
> program here:
>
>http://hashcollision.org/whalesong/examples/todo/todo.html
>
> work for as many browsers as I can.
>
>
> From my experiments:
>
>* Chrome, the fresh-off-the-shelf Mozilla nightly, and Konqueror
> can run this program fine.
>
>* Firefox non-nightlies fails with that crazy lexical scoping bug.
>
>* Mobile Safari on the iPad as well as the iPhone fails, but
> without any error message.
>
>* Browser on the Nexus One (Gingerbread) runs with no problems.
>
>* Browser on the Motorola Droid crashes.
>
>
> People with mobile browsers in particular: can you visit the page and
> report what you see?  That would be a big help.  Stack traces or any
> kind of debugging output would be golden.
>
>
> I don't have a concrete idea what's causing my compilation strategy to
> fail on the iOS devices.  My best guess so far is that its evaluator
> does not like to handle such large files: I observe that the iOS
> browser just stops in the middle and gives up.  If that's the case,
> I'll need to fracture the code into separate, independent JS files.
>
> _
>  For list-related administrative tasks:
>  http://lists.racket-lang.org/listinfo/users
>



-- 
-- 
Jens Axel Søgaard
_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/users

Re: [racket] Fwd: typo in signatures?

2011-10-03 Thread Jens Axel Søgaard
> Do the plus signs mean anything, or are they just typos?
>

Example:
   ...   means zero or more integers
   ...+   means one or more integers

Thus your example of max shows that max is a function
of two or more arguments.

-- 
Jens Axel Søgaard
_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/users

[racket] Looping and let-values

2011-10-23 Thread Jens Axel Søgaard
Hi All,

I was having fun with sequece-generate* and wrote this
program as an example of its use.

(let-values ([(first next) (sequence-generate* '(a b c))])
  (let loop ([first first] [next next])
(when first
  (display first) (newline)
  (call-with-values next loop

The   (let loop ([first first] [next next]) ... ) seems redundant.

Would it make sense for let-values to support the following?

(let-values loop ([(first next) (sequence-generate* '(a b c))])
  (when first
(display first) (newline)
(call-with-values next loop)))

-- 
Jens Axel Søgaard
_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/users

[racket] The orange turtle triangle is not moving

2012-02-26 Thread Jens Axel Søgaard
Hi All,

I have some 8th graders visiting my school. I have one hour in which I
intend to let them play with the turtles in Racket.

But - there seems to be a bug in the implementation.
A bug that puzzles me. It seems the commands are
interpreted different when entered in the definition
window versus the interaction window.

In short:  The turtle commands only move the orange triangle
if the commands are in the program - not if the same commands
are entered in the repl.

Consider this program:

#lang racket
(require graphics/turtles)
(turtles #t)
(draw 100)
(turn 90)

It correctly moved the turtle forward 100 pixels
drawing a line in the process, and then rotates the
turtle 90 degrees. Then an orange  triangle is drawn
showing the position of the turtle.

However if I now enter (forward 100) in the repl,
then the line is drawn but the orange triangle
stays in place.

Any ideas how I can fix this?

https://github.com/plt/racket/tree/master/collects/graphics

-- 
Jens Axel Søgaard

  Racket Users list:
  http://lists.racket-lang.org/users


[racket] Missing turtle

2012-02-26 Thread Jens Axel Søgaard
The problem seems to be, that the only place draw-turtle-icons
is called is in on-paint. This event is only called when

> Specification: Called when the canvas is exposed or
> resized so that the image in the canvas can be repainted.

And indeed if one issues commands in the repl and then resizes the
window, the orange triangle is updated.

-- 
Jens Axel Søgaard

  Racket Users list:
  http://lists.racket-lang.org/users


Re: [racket] Missing turtle

2012-02-26 Thread Jens Axel Søgaard
I have sent a bugfix to github.

The bugfix changes the width of the wipe-line to 2 pixels.
This may or may not be acceptable, but before this

(draw 100)
(turn 180)
(erase 100)

would produce a grey line.

-- 
Jens Axel Søgaard

  Racket Users list:
  http://lists.racket-lang.org/users


Re: [racket] x-expressions

2012-02-28 Thread Jens Axel Søgaard
2012/2/28 Johannes Brauer 

> Hi!
>
> In DrRacket version 5.02 this x-expression
>
> (validate-xexpr '(add x 2))
>
> is legal. In version 5.2 I get the error message
>
> Expected a string, symbol, number, comment, processing instruction, or
> list, given 2
>
> Can anyone explain this to me?
>

According to the grammar in the documentation a lone number is not an
x-expression. Use '(add x "2") instead.

 xexpr = string  |
(list<http://docs.racket-lang.org/reference/pairs.html?q=xexpression#(def._((quote._~23~25kernel)._list))>
 symbol 
(list<http://docs.racket-lang.org/reference/pairs.html?q=xexpression#(def._((quote._~23~25kernel)._list))>
 
(list<http://docs.racket-lang.org/reference/pairs.html?q=xexpression#(def._((quote._~23~25kernel)._list))>
 symbol string) ...) xexpr ...)  |
(cons<http://docs.racket-lang.org/reference/pairs.html?q=xexpression#(def._((quote._~23~25kernel)._cons))>
 symbol 
(list<http://docs.racket-lang.org/reference/pairs.html?q=xexpression#(def._((quote._~23~25kernel)._list))>
 xexpr ...))  | symbol  |
valid-char?<http://docs.racket-lang.org/xml/index.html?q=xexpression#(def._((lib._xml/main..rkt)._valid-char~3f))>
  | cdata  | misc
-- 
Jens Axel Søgaard

  Racket Users list:
  http://lists.racket-lang.org/users


Re: [racket] What is the equivalent of ToExpression in Mathematica?

2012-02-29 Thread Jens Axel Søgaard
2012/2/29 ashok bakthavathsalam 

> I am looking for something similar to 
> ToExpression<http://reference.wolfram.com/mathematica/ref/ToExpression.html> 
> that
> is available in Mathematica. I just want to convert a string to an
> expression, and evaluate the expression. As a first pass, my strings will
> include only numbers and arithmetic operators, and not even parentheses.
>
> If I need to write it, please point me in the direction of the appropriate
> pre-defined modules/definitions which I should use.
>

Maybe you can use this parser for infix expressions.
http://planet.racket-lang.org/package-source/soegaard/infix.plt/1/0/planet-docs/manual/index.html

Here is a small example (it takes a while for the library to install - it
seems it old Schematics test suite takes forever to install these days - I
need to switch to a builtin one).


#lang at-exp racket
(require (planet soegaard/infix)
 (planet soegaard/infix/parser))
(display (format "1+2*3 is ~a\n" @${1+2*3} ))

(parse-expression #'here (open-input-string "1+2*3"))

The output will be:
1+2*3 is 7
.#

The function parse-expression parses the expression in the string and
returns a syntax-object that resembles the output of ToExpression.

 --
Jens Axel Søgaard

  Racket Users list:
  http://lists.racket-lang.org/users


Re: [racket] Type-class-like idiom in Racket?

2012-03-05 Thread Jens Axel Søgaard
2012/3/5 Helmut Rohrbacher 

> Danny & Matthias,
>
> I hadn't known about structure properties. I think lumping enough
> syntactic sugar onto your syntax definitions, Matthais, might make it
> feasible to reproduce something to provide the functionality I'm looking
> for.
>
> The only thing is, how do you extend these properties to built-in types
> like LIST and VECTOR? I'm guessing that you'd need to wrap them in a
> user-defined type...
>

Or use structure properties to turn them into sequences (and then use for
and friends).

http://docs.racket-lang.org/reference/sequences.html?q=sequence%20property#(def._((lib._racket/private/base..rkt)._prop~3asequence))


-- 
Jens Axel Søgaard

  Racket Users list:
  http://lists.racket-lang.org/users


Re: [racket] cool things in Whalesong, part 2

2012-03-07 Thread Jens Axel Søgaard
>
> >> Can you be more explicit about what's cool here? I have a sense that it
> has to do with JS interacting with compiled racket, and I agree that that's
> very cool, but I could use a bit more hand-holding :).
>

After seeing the inter-frame communication example, I got an idea.
Is it possible to have two frames each running different Whalesong programs
communicating with each other?

-- 
Jens Axel Søgaard

  Racket Users list:
  http://lists.racket-lang.org/users


[racket] Using Maxima fra Racket

2012-03-08 Thread Jens Axel Søgaard
Hi All,

I am trying to send commands from Racket to Maxima (algebra system).
Here is a normal interaction with Maxima in the terminal:

soegaard$ /Applications/Maxima.app/Contents/Resources/maxima.sh
Maxima 5.25.1 http://maxima.sourceforge.net
using Lisp SBCL 1.0.47
Distributed under the GNU Public License. See the file COPYING.
Dedicated to the memory of William Schelter.
The function bug_report() provides bug reporting information.
(%i1) 1+2;
(%o1)  3
(%i2)

After displaying the welcome message, Maxima display the prompt "(%i1) ".
The I entered 1+2;.
Maxima then evaluated the expression and printed the line beginning with
(%o1).

Maxima has an option -s  that makes Maxima listen on a give port.
I have used this to write the following:

#lang racket
(require racket/tcp)
(define PORT 8082)

(let ([listener (tcp-listen PORT 1 #t)])
  (process (format "/Applications/Maxima.app/Contents/Resources/maxima.sh
-s ~a >/dev/null" PORT))
  (let-values ([(in out) (tcp-accept listener)])
(for ([i (in-range 6)]); there are 6 lines in the welcome
message
  (display (read-line in))
  (newline))
(display "prompt:\n")
(write (read in))   ; this displays the prompt (%i1)
(newline)
(write (read-char in)) ; eat whitespace
(newline)
(display "Prompt read correctly.\n")
(display "Sending command to Maxima.\n")
(display "1+2;\n" out) (flush-output out)
(display "Wait, before readin result.\n")
(sleep 1)
(display "Read and print the result one character at a time.\n")
(for ([i (in-range 6)])
  (display (peek-char in)) (display "."

This gives the following output when run in DrRacket:

pid=15314
Maxima 5.25.1 http://maxima.sourceforge.net
using Lisp SBCL 1.0.47
Distributed under the GNU Public License. See the file COPYING.
Dedicated to the memory of William Schelter.
The function bug_report() provides bug reporting information.
prompt:
(%i1)
#\space
Prompt read correctly.
Sending command to Maxima.
Wait, before readin result.
Read and print the result one character at a time.

(and then nothing is printed)

My problem is that I don't get any output back.
I have a feeling I am missing something obvious - but what?

-- 
Jens Axel Søgaard

  Racket Users list:
  http://lists.racket-lang.org/users


Re: [racket] Using Maxima fra Racket

2012-03-08 Thread Jens Axel Søgaard
2012/3/8 Neil Van Dyke 

Thanks for taking the time to look at the problem.

It sounds like Maxima and your Racket program are both trying to be the TCP
> listener.  Maybe "tcp-connect" instead of "tcp-listen"?
>

I am fairly sure that part is correct. I do receive the welcome message
from Maxima. And I took a peek in the Maxima code to see what -s does.
This comment is from the Maxima code:

;; Connect Maxima to a socket which has been opened by
;; some third party, typically a GUI program which supplies
;; input to Maxima.
;; Note that this code DOES NOT create a Maxima server:
;; Maxima is the client!


> Once that's working, for robustness, you might want to manage some TCP I/O
> buffers yourself, and use "sync" (or "sync/timeout" or similar) on the
> ports.  Using the buffers also makes it easier to look for some markers in
> the protocol without blocking.
>

I'll look into this. I did run into blocking problems in earlier versions
of my snippet.


> P.S., I know you used that "process" temporarily here, but for the benefit
> of people who see this later, they should try to use "process*" instead,
> and monitor the status of the ports and the process (possibly in the same
> "sync" as the TCP ports).
>

Ok.

/Jens Axel

  Racket Users list:
  http://lists.racket-lang.org/users


Re: [racket] Using Maxima fra Racket

2012-03-09 Thread Jens Axel Søgaard
Hi All,

I have found out what caused my problems.

   When starting Maxima with -s one must read the output from
   input port return by (tcp-accept listener) in the snippet.
   But one must write to the output port returned by
   (process (format "... maxima.sh -s ~a" PORT))
   in order to send commands to Maxima.

It seems somewhat fishy to me, so maybe I have omitted a Maxima flag.
I'll ask at the Maxima mailing list.

Neil: Thanks for the suggestion of using sync. It works really well.

/Jens Axel


2012/3/8 Jens Axel Søgaard 

> 2012/3/8 Neil Van Dyke 
>
> Thanks for taking the time to look at the problem.
>
> It sounds like Maxima and your Racket program are both trying to be the
>> TCP listener.  Maybe "tcp-connect" instead of "tcp-listen"?
>>
>
> I am fairly sure that part is correct. I do receive the welcome message
> from Maxima. And I took a peek in the Maxima code to see what -s does.
> This comment is from the Maxima code:
>
> ;; Connect Maxima to a socket which has been opened by
> ;; some third party, typically a GUI program which supplies
> ;; input to Maxima.
> ;; Note that this code DOES NOT create a Maxima server:
> ;; Maxima is the client!
>
>
>> Once that's working, for robustness, you might want to manage some TCP
>> I/O buffers yourself, and use "sync" (or "sync/timeout" or similar) on the
>> ports.  Using the buffers also makes it easier to look for some markers in
>> the protocol without blocking.
>>
>
> I'll look into this. I did run into blocking problems in earlier versions
> of my snippet.
>
>
>> P.S., I know you used that "process" temporarily here, but for the
>> benefit of people who see this later, they should try to use "process*"
>> instead, and monitor the status of the ports and the process (possibly in
>> the same "sync" as the TCP ports).
>>
>
> Ok.
>
> /Jens Axel
>
>

  Racket Users list:
  http://lists.racket-lang.org/users


[racket] Partion

2012-03-16 Thread Jens Axel Søgaard
Hi All,

I am looking for a list based algorithm, that solves this problem:

Input:A list xs of numbers.
Output: Two lists of numbers ys and zs whose
 lengths differ at most by one, and:

for all y in yz and z in zs:y<=z


A simple solution using sort is

 (split-at (sort xs <) (half (length xs))

but using sort must be inefficient.

Another try (that doesn't work):

(let ([m (median xs)])
(partition (λ (x) (<= x m)) xs))

To see the bug here,  try   xs = (1 2 2 2 2 2 2).
Since the median in this case is 2, partion will return
two values, one is xs and one is the empty list.

-- 
Jens Axel Søgaard


  Racket Users list:
  http://lists.racket-lang.org/users


Re: [racket] Partion

2012-03-16 Thread Jens Axel Søgaard
2012/3/16 Danny Yoo :

> Hmmm... Questions: why is a list-based approach a requirement?

Er. Well. A vector based solution would be fine too.

> Do the
> numbers share a special characteristic, such as being densely packed
> into a tight range?  If so, bucket sorting could be applied to get
> fast O(n) sorting at this stage.

The numbers are coordinates of the corners of bounding rectangles
of two-dimensional objects. I don't expect a particular distribution.

--
Jens Axel Søgaard


  Racket Users list:
  http://lists.racket-lang.org/users


Re: [racket] Partion

2012-03-16 Thread Jens Axel Søgaard
2012/3/16 Danny Yoo :

> Hmmm... the behavior of quicksort almost feels like what you want; in
> the optimal case, it's supposed to choose the median, and then
> partition elements into things bigger or less than the median.  You
> might be able to get away with an in-place quicksort that's stops
> early.  Your problem doesn't require a total sort, but rather just
> enough order that we can say that all the elements on the left half
> are smaller than all the elements on the right.

I just realized that I don't need to use the builtin partition to
split the list. I can just run through the list and collect elements
less or equal to the median until I have collected (half N) elements.

Apropos, should median and select (kth-element)  be in racket/list ?

--
Jens Axel Søgaard


  Racket Users list:
  http://lists.racket-lang.org/users


[racket] Snips displaying pdfs

2012-03-17 Thread Jens Axel Søgaard
Is it possible to display pdfs in snips without converting them to bitmaps?

I can see that pdf-drawing contexts are supported, but can't
find anything to display them.

--
Jens Axel Søgaard


  Racket Users list:
  http://lists.racket-lang.org/users


Re: [racket] Snips displaying pdfs

2012-03-18 Thread Jens Axel Søgaard
2012/3/17 Neil Van Dyke :
> Jens Axel Søgaard wrote at 03/17/2012 09:17 AM:
>
>> Is it possible to display pdfs in snips without converting them to
>> bitmaps?

> You might be able to implement this using Poppler.
>  http://en.wikipedia.org/wiki/Poppler_%28software%29

Looks like Poppler is the way to go.

I can now open a pdf-file and render it into a cairo_t context.
The code is attached. To test that the rendering works,
I saved it in a png, and then displayed it in a snip.

I am struggling with creating a bitmap directly from the cairo context.
Any pointers?

-- 
Jens Axel Søgaard


racket-poppler.rkt
Description: Binary data

  Racket Users list:
  http://lists.racket-lang.org/users


[racket] Are slider% callbacks called too often or too late?

2012-04-01 Thread Jens Axel Søgaard
Hi All,

I have a little problem with the attached program.
Maybe, I am not 100% sure, the slider% calls the call-back
more than once (maybe 4 times?) after the release of the mouse.
The behaviour puzzles me.

Is it the intended behaviour? If so, is there a better way
to use the slider, than the one in the attached program?

I found the following program by António Leitão from June 2011
on the mailing list, which shows this oddity.

(require racket/gui)
(define frame (new frame% [label "Example"]))
(new slider% [parent frame]
 [label "Test"]
 [min-value 0]
 [max-value 10]
 [callback (lambda (slider event)
 (display
  (format "~a@~a: ~a~%"
  (send event get-event-type)
  (send event get-time-stamp)
  (send slider get-value])

(send frame show #t)

On my computer,  if I run the program, and then move the
slider to 5 and release the mouse, I get this output:

slider@-273484745: 0
slider@-273484095: 1
slider@-273482097: 5
slider@-273482096: 5
slider@-273482096: 5
slider@-273482096: 5
slider@-273482096: 5


--
Jens Axel Søgaard


graphical-michaelis-menten.rkt
Description: Binary data

  Racket Users list:
  http://lists.racket-lang.org/users


Re: [racket] Are slider% callbacks called too often or too late?

2012-04-02 Thread Jens Axel Søgaard
An easy fix: Let the callback ignore calls, when the slider value
is the same as the last one.

Example:

(define substrate-slider
  (let ([last-value-seen -42])
(make-slider pane
 "[S]" 0 slider-max
 (lambda (slider event)
   (let ([n (send slider get-value)])
 (unless (= n last-value-seen)
   (set! last-value-seen n)
   (set! s0 (exact->inexact (* smax (/ slider-max) n)))
   (draw
 (λ () s0)
 (λ () smax

/Jens Axel


2012/4/1 Jens Axel Søgaard :
> Hi All,
>
> I have a little problem with the attached program.
> Maybe, I am not 100% sure, the slider% calls the call-back
> more than once (maybe 4 times?) after the release of the mouse.
> The behaviour puzzles me.
>
> Is it the intended behaviour? If so, is there a better way
> to use the slider, than the one in the attached program?
>
> I found the following program by António Leitão from June 2011
> on the mailing list, which shows this oddity.
>
> (require racket/gui)
> (define frame (new frame% [label "Example"]))
> (new slider% [parent frame]
>             [label "Test"]
>             [min-value 0]
>             [max-value 10]
>             [callback (lambda (slider event)
>                         (display
>                          (format "~a@~a: ~a~%"
>                                  (send event get-event-type)
>                                  (send event get-time-stamp)
>                                  (send slider get-value])
>
> (send frame show #t)
>
> On my computer,  if I run the program, and then move the
> slider to 5 and release the mouse, I get this output:
>
> slider@-273484745: 0
> slider@-273484095: 1
> slider@-273482097: 5
> slider@-273482096: 5
> slider@-273482096: 5
> slider@-273482096: 5
> slider@-273482096: 5

--
Jens Axel Søgaard


  Racket Users list:
  http://lists.racket-lang.org/users


[racket] Puzzled

2012-04-02 Thread Jens Axel Søgaard
The following program shows a slider.
Why does the slider stop working, when I uncomment the display line?

#lang racket
(require racket/gui)

(define integer-slider%
  (class* slider% ()
(super-new)
(inherit get-value)
(define down? #f)
(define/override (on-subwindow-event receiver event)
  (begin0
(super on-subwindow-event receiver event)
; (display (get-value)) (display " ")


(define frame (new frame% [label "Example: How to use real-slider%"]))
(define real-slider
  (new integer-slider%
   [parent frame] [label "x:"]
   [min-value 1] [max-value 100] [init-value 50]))

(send frame show #t)


--
Jens Axel Søgaard


  Racket Users list:
  http://lists.racket-lang.org/users


Re: [racket] Puzzled

2012-04-03 Thread Jens Axel Søgaard
Hi,

Thanks for the explanation. It makes sense now. Before it was just odd.

I was planning to reuse slider% to make a slider that will snap to a set
of discrete values (not necessarily with a fixed distance between them).

Would the simplest implementation strategy be to implement it from scratch
(using a canvas to draw the line and handle) rather than reuse slider% ?

/Jens Axel

2012/4/2 Matthew Flatt :
> Sorry for the delay! I see that the same question went unanswered in
> 2011, too, although the answer is available from September 2009:
>
>  http://lists.racket-lang.org/users/archive/2009-September/035316.html
>
> That old message's prediction that a new `racket/gui' (formerly MrEd)
> would solve the problem turned out to be overly optimistic. The
> mismatch between eventspaces and GUI toolkits turns out to be deep
> enough that the completely reimplemented `racket/gui' is only a little
> better than the old implementation.
>
>
> To recap, the problem is that the underlying GUI toolkit (Cocoa, Gtk,
> or Win32) takes control when the slider is clicked, and the toolkit
> does not return control until the slider is released. The `racket/gui'
> library's handling of callbacks is obligated to stay within the same
> Racket thread as when the slider was initially clicked, because nested
> toolkit calls may depend on the enclosing dynamic context for various
> reasons. Consequently, if a slider callback (or some indirect callback,
> such as `on-subwindow-event') synchronizes in such a way that other
> Racket thread must first proceed, then the continuation of the callback
> is delayed by `racket/gui', and control is returned immediately to the
> underlying toolkit. When the toolkit relinquishes control after
> handling the click, any delayed callbacks can be completed.
>
> In the case of printing output that will appear in DrRacket,
> synchronization is required with DrRacket's GUI thread. That's why
> printing makes your example get stuck.
>
>
> (A reader who hasn't heard of this problem may now be tempted to
> suggest a workaround that involves multiple OS level threads, or
> something like that. All I can say is that I haven't been able to make
> anything like that work, despite two serious attempts.)
>
>
> At Mon, 2 Apr 2012 22:37:11 +0200, Jens Axel Søgaard wrote:
>> The following program shows a slider.
>> Why does the slider stop working, when I uncomment the display line?
>>
>> #lang racket
>> (require racket/gui)
>>
>> (define integer-slider%
>>   (class* slider% ()
>>     (super-new)
>>     (inherit get-value)
>>     (define down? #f)
>>     (define/override (on-subwindow-event receiver event)
>>       (begin0
>>         (super on-subwindow-event receiver event)
>>         ; (display (get-value)) (display " ")
>>         ))))
>>
>> (define frame (new frame% [label "Example: How to use real-slider%"]))
>> (define real-slider
>>   (new integer-slider%
>>        [parent frame] [label "x:"]
>>        [min-value 1] [max-value 100] [init-value 50]))
>>
>> (send frame show #t)
>>
>>
>> --
>> Jens Axel Søgaard
>>
>> 
>>   Racket Users list:
>>   http://lists.racket-lang.org/users



-- 
--
Jens Axel Søgaard


  Racket Users list:
  http://lists.racket-lang.org/users


[racket] How to use reparent - no such method: adopt-child for class

2012-04-03 Thread Jens Axel Søgaard
Hi All,

My attempt to implement a slider with snapable values, ticks and
keyboard + and -
is almost done. The basic slider functionality works.

This will create a slider, where with ticks at 0, 10, ... ,
And the user can only select values from 0.0, 12.5, ... .

(define basic-slider
  (new basic-slider%
   [parent frame]
   [tick-values(list 0 10 20 30 40 50 60 70 80 90 100)]
   [snap-values  (list 0.0 12.5 25.0 37.5 50.0 62.5 75.0 87.5 100.0))]
   [init-value 20.0]))

The basic-slider% is implemented as a subclass of canvas% implementing
the control<%> interface.

The builtin slider% supports a label to the left of the actual slider.

I therefore attempted to make a new class that within
a horizontal pane would hold both a message for the label
and the basic-slider. In order to this I tried to use reparent,
but got the error message

send: no such method: adopt-child for class: .../private/wxpanel.rkt:723:4

(define basic-slider-with-label%
  (class* basic-slider% (control<%>)
(init parent)
(define pane (new horizontal-pane% [parent parent]))
(define message (new message% [parent pane] [label "foo"]))
(super-new [parent pane])
(send this reparent pane)
(new message% [parent pane] [label "bar"])))

I suspect this is a bug?

However, I might not need reparent at all.
Is there a better way to add the message to the left of the
basic slider?

-- 
Jens Axel Søgaard


  Racket Users list:
  http://lists.racket-lang.org/users


Re: [racket] How to use reparent - no such method: adopt-child for class

2012-04-03 Thread Jens Axel Søgaard
I forgot to attach the program.

/Jens Axel


2012/4/3 Jens Axel Søgaard :
> Hi All,
>
> My attempt to implement a slider with snapable values, ticks and
> keyboard + and -
> is almost done. The basic slider functionality works.
>
> This will create a slider, where with ticks at 0, 10, ... ,
> And the user can only select values from 0.0, 12.5, ... .
>
> (define basic-slider
>  (new basic-slider%
>       [parent frame]
>       [tick-values    (list 0 10 20 30 40 50 60 70 80 90 100)]
>       [snap-values  (list 0.0 12.5 25.0 37.5 50.0 62.5 75.0 87.5 100.0))]
>       [init-value 20.0]))
>
> The basic-slider% is implemented as a subclass of canvas% implementing
> the control<%> interface.
>
> The builtin slider% supports a label to the left of the actual slider.
>
> I therefore attempted to make a new class that within
> a horizontal pane would hold both a message for the label
> and the basic-slider. In order to this I tried to use reparent,
> but got the error message
>
> send: no such method: adopt-child for class: .../private/wxpanel.rkt:723:4
>
> (define basic-slider-with-label%
>  (class* basic-slider% (control<%>)
>    (init parent)
>    (define pane (new horizontal-pane% [parent parent]))
>    (define message (new message% [parent pane] [label "foo"]))
>    (super-new [parent pane])
>    (send this reparent pane)
>    (new message% [parent pane] [label "bar"])))
>
> I suspect this is a bug?
>
> However, I might not need reparent at all.
> Is there a better way to add the message to the left of the
> basic slider?
>
> --
> Jens Axel Søgaard



-- 
--
Jens Axel Søgaard


slider.rkt
Description: Binary data

  Racket Users list:
  http://lists.racket-lang.org/users


Re: [racket] Moving beyond world/universe

2012-04-09 Thread Jens Axel Søgaard
Hi Stephen,

Here is how I would do it.

/Jens Axel

#lang racket/gui

;;;
;;; WORLD
;;;

(define-struct world (lines))
(define the-world (make-world '((0 . 0) (0 . 300) (250 . 250) (150 .
176) (10 . 4) (280 . 10

;;;
;;; USER LAND
;;;

(define (on-mouse-event world event)
  (if (and (send event get-left-down)
   (send event moving?)
   #; (send event button-changed?))
  (let ((x (send event get-x))
(y (send event get-y)))
(make-world (cons (cons x y) (world-lines world
  world))

(define (on-paint world dc)
  (send dc draw-lines
(map pair->point (world-lines world

(define (pair->point p)
  (make-object point% (car p) (cdr p)))


;;;
;;; SYSTEM
;;;

(define user:on-paint on-paint)

(define diagramframe (new frame% [label "paint"] [width 300] [height
300] [x 1000][y 300]))

(define paintcanvas%
  (class canvas%
(inherit get-dc refresh)
(super-new)

(define/override (on-paint)
  (send (get-dc) suspend-flush)
  (user:on-paint the-world (get-dc))
  (send (get-dc) resume-flush))

(define/override (on-event mouse-event)
  (let* ([old-world the-world]
 [new-world (on-mouse-event the-world mouse-event)])
(if (eq? old-world new-world)
(super on-event mouse-event)
(begin
  (set! the-world new-world)
  (refresh)))

(define paintcanvas (new paintcanvas% [parent diagramframe]))
(send diagramframe show #t)



2012/4/9 Stephen De Gabrielle :
> Hi,
>
> I thought I'd try a simple GUI app using the world/universe mutation-free
> approach,  but trying to implement the 'world/universe' program design
> myself.
>
> I've got my little sketch below, but I quickly came to conclusion that while
> I could use the teachpack, I don't know how to achieve the teachpack
> functionality myself.
>
> I'm guessing I should use continuations, but that doesn't seem to be the
> approach in the universe.rkt source.
>
> I could always just stuff the program into the canvas class, (as earlier
> games like slidey and same seem to do), but I really want to get a handle
> on  how to implement the 'world/universe' style of program control.
>
> Any suggestons would be appreciated.
>
> Kind regards,
>
> Stephen
>
>
> 
> #lang racket/gui
>
> ; simple drawing program
> ; mousedown starts recording a list of points
> ; mousechanged starts recording a new list
> ; paint callback paints the list of lists as lines.
>
> (define diagramframe (new frame% [label "paint"] [width 300] [height 300] [x
> 1000][y 300]))
>
> ;(define lines '(((0 . 0) (0 . 300) (250 . 250) (150 . 176
> (define lines '(((0 . 0) (0 . 300) (250 . 250) (150 . 176))
>     ((10 . 4) (280 . 10
>
> (define paintcanvas%
>   (class canvas%
>     (init-field mouse-event-callback)
>     (super-new)
>     (define dc (send this get-dc))
>     (define/override (on-event mouse-event)
>   (mouse-event-callback mouse-event
>
> (define (paint-cb c dc)
>   (for-each (λ (line) (send dc draw-lines line)) lines))
>
> (define (me-cb mouse-event)
>   (let ((x (send mouse-event get-x))
>     (y (send mouse-event get-y)))
>     (when (and (send mouse-event get-left-down)
>    (send mouse-event moving?))
>   (if (send mouse-event button-changed?)
>   ; if true append as new list
>   '()
>   ; if false append existing list
>   '(
>   )
>
> (define Paintcanvas (new paintcanvas%
>  [parent diagramframe]
>  [paint-callback paint-cb]
>          [mouse-event-callback me-cb]))
>
> (define (main world)
>  (when world (main (??? world)))
>   (send diagramframe show #t))
>
> (main lines)
>
> (send diagramframe show #t)
>
> ;;-
>
> 
>  Racket Users list:
>  http://lists.racket-lang.org/users
>

--
Jens Axel Søgaard


  Racket Users list:
  http://lists.racket-lang.org/users


Re: [racket] Beginning macro assignments?

2012-04-27 Thread Jens Axel Søgaard
How about list comprehension?

I envision giving them the 5 rules in "The Implementation of
Functional Programming Languages" in Racket notation and some examples
in order to get them started.

See the bottom of:

http://research.microsoft.com/en-us/um/people/simonpj/papers/slpj-book-1987/PAGES/130.HTM

/Jens Axel

2012/4/27 Stephen Bloch :
> I'm teaching a sophomore-level "Principles of Programming Languages" course.  
> We've been working through various chapters of PLAI, but I want to spent the 
> last week or so of the semester on macros, using the "Racket Guide to Macros" 
> at http://docs.racket-lang.org/guide/macros.html .  We'll also be talking 
> about the C preprocessor as another example of "macros".
>
> Does anybody have some good reasonably-easy macro-writing exercises I could 
> assign my students?  Something that's not actually solved in the Racket 
> Guide, but is of comparable difficulty.
>
> For that matter, if you have good reasonably-easy exercises for the C 
> preprocessor, that would be helpful too.
>
>
> Stephen Bloch
> sbl...@adelphi.edu
>
>
> 
>  Racket Users list:
>  http://lists.racket-lang.org/users



-- 
--
Jens Axel Søgaard


  Racket Users list:
  http://lists.racket-lang.org/users


[racket] Constructors for sequences

2012-04-29 Thread Jens Axel Søgaard
Given a sequence is there way to get the "constructor" of the sequence?

(sequence-constructor (list 1 2 3))  = list
(sequence-constructor (vector 1 2 3))  = vector
etc

I'd like to use it for a declare-mappable macro that extends functions
of one argument
to map over sequences. As in (sin (list 1 2 3)) = (list (sin 1) (sin
2) (sin 3)).

The sequence-map function is close, but it produces sequences.
Now I could of course hard code the usual suspects, but it seems
somewhat inelegant.

--
Jens Axel Søgaard


  Racket Users list:
  http://lists.racket-lang.org/users


Re: [racket] Constructors for sequences

2012-04-29 Thread Jens Axel Søgaard
2012/4/29 Galler :

>> (distribute sin list 1 2 3)
> (0.8414709848078965 0.9092974268256817 0.1411200080598672)

This makes the constructor explicit. That's what I want to avoid.

The problem is that a user can define his own type of sequence,
and I'd like my function work with user defined sequences too.

-- 
Jens Axel Søgaard


  Racket Users list:
  http://lists.racket-lang.org/users


Re: [racket] Constructors for sequences

2012-04-30 Thread Jens Axel Søgaard
2012/4/30 Asumu Takikawa :
> On 2012-04-29 12:43:48 -0400, Matthias Felleisen wrote:
>> What you're really saying is that sequence-map uses the wrong kind of type. 
>> Specifically, it should be polymorphic in the sequence constructor instead 
>> of mapping everything to the top of the class hierarchy (sequence).
>
> I don't think this is just a type issue. The sequence that is returned
> by `sequence-map` is lazy, even if the original sequence was not. That's
> why you can't get the original type.

Good point.

However, I don't mind doing some manual labor:

(define (map-sqr a-sequence)
(let ([construct (sequence-constructor a-sequence)])
   (apply construct (sequence->list (sequence-map sqr a-sequence)

(map-sqr '(1 2 3))  ; => (1 4 9)
(map-sqr #(1 2 3)) ; => #(1 4 9)

-- 
Jens Axel Søgaard


  Racket Users list:
  http://lists.racket-lang.org/users


Re: [racket] Mutable state vs RAM on fire

2012-05-02 Thread Jens Axel Søgaard
I believe the problem is the representation, you have chosen
for polynomials in the first program.

I am interested in hearing if the following representation gives a
better results:

#lang racket
(require (only-in srfi/1 span))

;;;
;;; Dense polynomials represented as lists.
;;;

(define-struct poly (deg coefs) #:transparent)
;   deg is the degree
;   coefs is a list of coeffecients.
;   p(x) = sum ci * x^i is represented as (poly n (list c0 c1 ... cn))

(define (degree p)
  (poly-deg p))

(define (remove-leading-zeros xs)
  (cond [(empty? xs) xs]
[(zero? (car xs)) (remove-leading-zeros (cdr xs))]
[else xs]))

(define (trim-trailing-zeros xs)
  (reverse (remove-leading-zeros (reverse xs

(define (coef-length->degree cs)
  (if (empty? cs)
  -inf.0
  (- (length cs) 1)))

(define (poly-add p1 p2)
  (if (< (degree p1) (degree p2))
  (poly-add p2 p1)
  (let* ([cs (trim-trailing-zeros
  (for/list ([c1 (in-list (poly-coefs p1))]
 [c2 (in-list (append (poly-coefs p2)
  (build-list (-
(degree p1) (degree p2))
  (λ (i) 0])
(+ c1 c2)))])
(poly (coef-length->degree cs) cs

(define (poly-mul p1 p2)
  (define (sum-same-degree i dcs)
(if (empty? dcs)
'()
(let-values ([(deg-i deg-larger) (span (λ (dc) (= (car dc) i)) dcs)])
  (cons (apply + (map cdr deg-i))
(sum-same-degree (+ i 1) deg-larger)
  (let* ([dcs
  (for*/list ([(c1 i) (in-indexed (in-list (poly-coefs p1)))]
  [(c2 j) (in-indexed (in-list (poly-coefs p2)))])
(cons (+ i j) (* c1 c2)))]
 [dcs (sort dcs < #:key car)]
 [cs (sum-same-degree 0 dcs)])
(poly (coef-length->degree cs) cs)))

/Jens Axel


2012/5/2  :
>
> Hey all,
>
> Been playing around with some code to multiply polynomials to calculate dice 
> probabilities.
> Is based on a paper by Doron Zeilberger that I read years ago and can't find 
> at the moment.
>
> My first attempt represented polynomials as lists of coefficient/exponent 
> pairs.
> I tried to make it completely functional, with no set! operations.  You can 
> see it here:
>
> https://github.com/TurtleKitty/Dice/blob/2fff16e198cb84d725c786ecc624fb9b9468e778/dice.rkt
>
> It worked, but only to a point.  At 9 or 10 dice, it started blowing up the 
> RAM in my machine.
> I swear I smelled smoke.  It grabbed like 4G and slowed to a crawl.
>
> Knowing that the Perl and Javascript versions of this program can calculate 
> distributions for 300 dice in the space of a heartbeat,
> I rewrote the thing to use vectors instead, and altered the polynomial 
> multiplication function to use (begin) and (vector-set!):
>
> https://github.com/TurtleKitty/Dice/blob/67c2b49707132395f73b43afe111e3904b3898f2/dice.rkt
>
> It too now calculates three hundred dice without breaking a sweat, but... I 
> feel dirty.
> Can anyone recommend a functional approach that won't melt my motherboard?
> I'm considering hashes, since they have the immutable version of hash-set 
> that vectors seem to lack, but I thought I'd ask the experts.
>
>
> Thanks,
> turtlekitty
> (There might be a library for this already. This is more of an exercise for 
> me than a utility.)
> 
>  Racket Users list:
>  http://lists.racket-lang.org/users



-- 
--
Jens Axel Søgaard


  Racket Users list:
  http://lists.racket-lang.org/users


Re: [racket] Mutable state vs RAM on fire

2012-05-03 Thread Jens Axel Søgaard
2012/5/3 Chris Stephenson :
> Isn't this just a question of choice of data representation?
>
> Once you drop the explicit powers from the representation and store
> least significant coefficient first, then the racket program becomes
> extremely simple.
>
> One reason Racket goes slower is that it use big ints while perl and
> javascript will both operate mod 2^32. A thousand polynomials multiplied
> together makes for some really *big* ints.

This is a very good point.

I modified my code to represent the coeffecients using floating point numbers.
At the same time I switched to unsafe floating point operations, and
added contracts to prevent disasters.

/Jens Axel

#lang racket
(require (only-in srfi/1 span drop-while)
 racket/unsafe/ops
 (planet williams/science/unsafe-ops-utils))

(provide
 (rename-out [poly-coefs coeffecients])
 (contract-out
  (rename Poly poly (-> fixnum? (listof real?) poly?))
  [poly-add (-> poly? poly? poly?)]
  [poly-mult (-> poly? poly? poly?)]
  [degree (-> poly? number?)]))

;;;
;;; Dense polynomials with floating number coeffecients represented as lists.
;;;

(define-struct poly (deg coefs) #:transparent)
;   deg is the degree
;   coefs is a list of coeffecients.
;   p(x) = sum ci * x^i is represented as (poly n (list c0 c1 ... cn))

(define (Poly d cs)
  (poly d (map real->float cs)))

(define (degree p)
  (poly-deg p))

(define (trim-trailing-zeros xs)
  (reverse (drop-while (λ (x) (unsafe-fl= x 0.0)) (reverse xs

(define (coef-length->degree cs)
  (if (empty? cs)
  -inf.0
  (- (length cs) 1)))

(define (poly-add p1 p2)
  (if (< (degree p1) (degree p2))
  (poly-add p2 p1)
  (let* ([cs (trim-trailing-zeros
  (for/list ([c1 (in-list (poly-coefs p1))]
 [c2 (in-list (append (poly-coefs p2)
  (build-list (-
(degree p1) (degree p2))
  (λ (i) 0.0])
(unsafe-fl+ c1 c2)))])
(poly (coef-length->degree cs) cs

(define (poly-mult p1 p2)
  (define (sum-same-degree i dcs)
(if (empty? dcs)
'()
(let-values ([(deg-i deg-larger) (span (λ (dc) (unsafe-fx=
(car dc) i)) dcs)])
  (cons (foldl (λ (p sum) (unsafe-fl+ (cdr p) sum)) 0.0 deg-i)
(sum-same-degree (+ i 1) deg-larger)
  (let* ([dcs
  (for*/list ([(c1 i) (in-indexed (in-list (poly-coefs p1)))]
  [(c2 j) (in-indexed (in-list (poly-coefs p2)))])
(cons (+ i j) (unsafe-fl* c1 c2)))]
 [dcs (sort dcs < #:key car)]
 [cs (sum-same-degree 0 dcs)])
(poly (coef-length->degree cs) cs)))


  Racket Users list:
  http://lists.racket-lang.org/users


[racket] In need of flexpt

2012-05-06 Thread Jens Axel Søgaard
I am missing flexpt in racket/flonum.

I could live without, and use one of those below.
However it looks as a natural operation to have in racket/flonum.

(define (flexpt1 a x)
  (real->float (expt a x)))

(define (flexpt2 a x)
  (flexp (fl* x (fllog a

The second is about twice as fast as the second,
but sacrifices numeriacal precision.

--
Jens Axel Søgaard


  Racket Users list:
  http://lists.racket-lang.org/users


Re: [racket] In need of flexpt

2012-05-06 Thread Jens Axel Søgaard
2012/5/7 Matthew Flatt :
> I'd expect `flexpt' to be the same as `expt', but constrained to flonum
> arguments, which would make it the same as
>
>  (define (flexpt a x)
>   (if (and (flonum? a) (flonum? x))
>       (expt a x)
>       (error ...s)))
>
> I agree that it would make a fine addition to `racket/flonum', but is
> that what you had in mind?

Yes, exactly.

/Jens Axel


  Racket Users list:
  http://lists.racket-lang.org/users


Re: [racket] Snips displaying pdfs

2012-05-07 Thread Jens Axel Søgaard
Hi Michael,

It would be great if you turned it into a Planet package. I had no immediate
need for pdfs, so I put it on hold.

The code attached to the old message rendered the pdf into a png on disc,
and then loaded the png as a snip.

Since then Matthew added get-handle to Racket, so now one can render
a pdf directly to a bitmap without touching the disc.

I have uploaded the latest version here:

https://github.com/soegaard/this-and-that/tree/master/racket-poppler

It needs a bit of work though...

Currently it simply renders the file bla.pdf into a bitmap that
is then displayed in DrRacket.

Note: You need a fairly recent build of DrRacket.
  The latest stable release is not new enough.

/Jens Axel

2012/5/7 Michael W :
> This is wonderful. Do you mind if I publish a planet package
> using this code?
>
> 2 months ago on Sunday, Mar 18, 08:29AM, Jens Axel Søgaard wrote:
>> 2012/3/17 Neil Van Dyke :
>> > Jens Axel Søgaard wrote at 03/17/2012 09:17 AM:
>> >
>> >> Is it possible to display pdfs in snips without converting them to
>> >> bitmaps?
>>
>> > You might be able to implement this using Poppler.
>> >  http://en.wikipedia.org/wiki/Poppler_%28software%29
>>
>> Looks like Poppler is the way to go.
>>
>> I can now open a pdf-file and render it into a cairo_t context.
>> The code is attached. To test that the rendering works,
>> I saved it in a png, and then displayed it in a snip.
>>
>> I am struggling with creating a bitmap directly from the cairo context.
>> Any pointers?
>>
> 
>  Racket Users list:
>  http://lists.racket-lang.org/users



-- 
--
Jens Axel Søgaard


  Racket Users list:
  http://lists.racket-lang.org/users


Re: [racket] Snips displaying pdfs

2012-05-07 Thread Jens Axel Søgaard
2012/5/8 Michael W :
> Sure, but I mean, is there a better way to get at a dc<%>'s cairo
> context than (require racket/draw/private/local) ? From what I
> understand, those areas aren't meant to be used by third-party
> libraries, and definitely not by planet packages. Not all dc<%>s
> are even backed by cairo contexts...

I believe you want get-handle. It will give you the surface of a bitmap,
and you can then get a context.

(let* ([bitmap(make-bitmap WIDTH HEIGHT)]  ; works
   [filename
"/Users/soegaard/Dropbox/GitHub/this-and-that/racket-poppler/bla.pdf"]
   [document  (poppler_document_new_from_file (string-append
"file:" filename) #f #f)]
   [page  (poppler_document_get_page document 0)]
   [surface   (send bitmap get-handle)]
   [context   (cairo_create surface)])
  (cairo_scale context 2.0 2.0)
  (poppler_page_render page context)
  (make-object image-snip% bitmap))

This example is from

https://github.com/soegaard/this-and-that/blob/master/racket-poppler/racket-poppler.rkt

/Jens Axel

>
> 16 minutes ago, Eli Barzilay wrote:
>> Three hours ago, Michael W wrote:
>> >
>> > I'm not rasterizing to a bitmap% or anything like that. Instead,
>> > I'm asking poppler to draw directly to the dc<%>'s cairo context
>> > (Eli and Matthew are probably cringing), which means that you can
>> > render to arbitrary dc<%> objects at the cost of being much more
>> > hacky than your version.
>>
>> I don't know about "hacky" -- it just sounds like it'll invoke the
>> library for every redraw, which would be overall slower than going
>> through a bitmap that saves the results.
>>
> 
>  Racket Users list:
>  http://lists.racket-lang.org/users



-- 
--
Jens Axel Søgaard


  Racket Users list:
  http://lists.racket-lang.org/users


Re: [racket] `def' ?

2012-05-11 Thread Jens Axel Søgaard
2012/5/11 Asumu Takikawa :
> Funny that this came up here, since just the other day I saw that the
> latest release of Gauche has this feature, but using the $ identifier:
>  http://practical-scheme.net/gauche/

Here is the manual entry:

http://practical-scheme.net/gauche/man/gauche-refe_24.html#index-_0024

-- 
Jens Axel Søgaard


  Racket Users list:
  http://lists.racket-lang.org/users


Re: [racket] `def' ?

2012-05-12 Thread Jens Axel Søgaard
I have amused myself with implementing this and other brevity constructs
useful for working with strings, vectors and other sequences.

In the repl one can now write:

(define-struct person (first-name last-name age height) #:transparent)
(define persons
(vector (person "John" "Doe" 42 1.80)
 (person "Jane" "Dae" 43 1.81)))
(define i 1)

(string (@ persons i .first-name 0) (@ persons i .last-name 0))

The file string-lang.rkt  implements a form {...} that allows one
one to reference the i'th element of lists, vectors, strings etc using
the syntax {v i}.

For substrings, sublists and subvectors and subsequences one can write {v i j}.

See the test file for examples.


There is one problem though.

The syntax
  {john .age}  should evaluate as (person-age john)
since john is an instance of a person structure.

Using information from structure-type-info I can construct the
identifier person-age, but I can not figure how to retrieve the
actual accessor without using eval.

This means that {john .age} only works in the repl and not
in a module context.

Any pointers for improving the macro dot (which implements this)
is appreciated.

-- 
Jens Axel Søgaard


2012/5/10 Matthias Felleisen :
>
> Thanks for the nice illustration. It would be
>
> (define initials
>  (string (string-ref (id-firstname (vector-ref person i)) 0)
>          (string-ref (id-lastname (vector-ref person i)) 0)))
>
> but even with that we don't get the density of some path expression:
>
> (define initials (string (@ person i firstname) (@ person i lastname)))
>
> And now we're comparing with
>
> initials = person[i].firstname[0] + person[i].lastname[0]
> or
> initials = (@ person i firstname) + (@ person i lastname)
>
> Hmph.
>
>
>
> On May 10, 2012, at 5:18 PM, Justin Zamora wrote:
>
>> In my experience, the heaviness of Racket doesn't come from words like
>> "define", etc.  It comes in certain categories of programs that deal
>> extensively with strings, vectors, and structured data.  For example,
>>
>> initials = person[i].firstname[0] + person[i].lastname[0]
>>
>> This is very readable and useful.  It can be written quickly and is
>> read and understood easily The overloading of "+" (or your operator of
>> choice) and the implicit coercion of characters to strings is exactly
>> what is wanted here.  Even evaluating person[i] more than once doesn't
>> clutter up the expression.
>>
>> Compare this to the equivalent Racket:
>>
>> (define initials
>>  (string-append (string (string-ref (id-firstname (vector-ref person i)) 0))
>>                 (string (string-ref (id-lastname (vector-ref person i)) 0
>>
>> For this sort of thing, the Racket version is much harder to write,
>> read, and verify.  It would be nice to have something akin to
>> at-expressions that would allow such expressions to be written more
>> clearly.
>>
>> Justin
>>
>> On Thu, May 10, 2012 at 4:00 PM, Matthias Felleisen
>>  wrote:
>>>
>>> I will assert something about readability:
>>>
>>>  Racket programs look heavy when compared with Haskell programs.
>>>
>>> This is probably true for Python instead of Haskell, too. It is also true 
>>> for ML. I conjecture that part of that heaviness comes from wide lines, 
>>> long names, deep nesting. Who knows. I don't even know how to measure this 
>>> kind of property.
>>>
>>> At this point, I can express certain ideas more easily in Racket than in 
>>> Haskell, Python, ML or whatever, which is why I am fine. But if this 
>>> advantage ever disappeared, heaviness would definitely be a factor to weigh.
>>>
>>> -- Matthias
>>>
>>>
>>>
>>>
>>>
>>>
>>> On May 10, 2012, at 3:49 PM, ozzloy-racket-users wrote:
>>>
>>>> i didn't assert that word length has nothing to do with readability, just 
>>>> that word frequency has more impact on reading time than word length.
>>>>
>>>> On Thu, May 10, 2012 at 3:39 PM, Luke Vilnis  wrote:
>>>> I can only speak for myself but I think it's a bit much to assert that 
>>>> word length has nothing to do with readability. Heck, maybe that's even 
>>>> true for you, but not for everyone. I have certainly felt it to be an 
>>>> issue. If the "define" keyword was 50 letters long it would definitely 
>>>> have an impact on my ability to read code - it seems to be an issue of 
>>>> degree, not existence.
>>>>
>>

Re: [racket] `def' ?

2012-05-12 Thread Jens Axel Søgaard
2012/5/11 Ray Racine 

> Give '{' yada '}' definable language semantics in the sense of #lang yada.
>
> Similar to SML-NJ Quote/Antiquote but leveraging Rackets more robust
> built-in language support.
>
> So a source file could be.
>
> ==
> #lang racket
> #lang {{ formula }}
>
> (define x 3)
> (define y 2)
>
> (define z {{ log (x + y) }})
>
> #lang {{ datalog }} ;; switch datalog language
>
> (define result {{
>   ancestor(A, B) :- parent(A, B).   ancestor(A, B) :-   parent(A, C), D =
> C, ancestor(D, B).   parent(john, douglas).   parent(bob, john).
> ancestor(A, B)?
> }} )
>
> #lang {{ formula }} ;; back to math formula
>
> (define ans (some-procedure result {{ z^2 + 42 }}))
> ===
>
> just works.
>
>
Ooh. Nice idea.

-- 
Jens Axel

  Racket Users list:
  http://lists.racket-lang.org/users


Re: [racket] `def' ?

2012-05-12 Thread Jens Axel Søgaard
2012/5/12 Matthias Felleisen :
>
> On May 12, 2012, at 12:54 PM, Jens Axel Søgaard wrote:
>
>> The syntax
>>  {john .age}  should evaluate as (person-age john)
>> since john is an instance of a person structure.
>>
>> Using information from structure-type-info I can construct the
>> identifier person-age, but I can not figure how to retrieve the
>> actual accessor without using eval.
>>
>> This means that {john .age} only works in the repl and not
>> in a module context.
>>
>> Any pointers for improving the macro dot (which implements this)
>> is appreciated.
>
>
> Since {john .age} is syntax, you might be able to grab the namespace at that
> point and use the namespace for an evaluation.

I tried using namespace-anchor for that purpose, but couldn't figure
out how to.

> ;; ---
>
> My preferred alternative is to equip structs that should work with this 
> syntax with
> a prop so that I can look up the accessor.

Been down that road before ;-)

http://lists.racket-lang.org/users/archive/2007-March/016756.html

/Jens Axel


  Racket Users list:
  http://lists.racket-lang.org/users


[racket] paren-shape

2012-05-13 Thread Jens Axel Søgaard
Hi All,

I am playing around with the paren-shape syntax property
in order to use {} for polynomials.

The case {+ p q r ...} is causing me problems.

I have reduced the problem to the example below.

I'd like {+ 2 3 5} to expand to (* (* 2 3) 5) and thus evaluate to 30.
However as is {+ 2 3 5} expands to (#%app + (#%app * '2 '3) '5)
which gives 11.

What have I missed?

/Jens Axel


#lang racket

(module huh racket
  (provide (rename-out [app #%app]))

  (define-for-syntax (curlify stx)
(syntax-property stx 'paren-shape #\{))

  (define-for-syntax (curly? stx)
(let ([p (syntax-property stx 'paren-shape)])
  (and p (eqv? p #\{

  (define-syntax (app stx)
(syntax-case stx (+)
  [{_ + p q}
   (curly? stx)
   (syntax/loc stx (* p q))]
  [{_ + p q r ...}
   (curly? stx)
   (curlify #'{app + (* p q) r ...})]
  [(_ . more)
   (syntax/loc stx (#%app . more))])))

(require 'huh)
{+ 2 3 5}

  Racket Users list:
  http://lists.racket-lang.org/users


Re: [racket] paren-shape

2012-05-13 Thread Jens Axel Søgaard
2012/5/13 Danny Yoo :
> Does this apply?
>  http://lists.racket-lang.org/dev/archive/2012-March/009205.html

Yes!

The test for curliness must take the (cons orig new)
new possibility into account, and then it just works.

Thanks.

/Jens Axel

(define-for-syntax (curly? stx)
(let ([p (syntax-property stx 'paren-shape)])
  (and p (or (eqv? p #\{)
 (and (pair? p)
  (or (eqv? (car p) #\{)
  (eqv? (cdr p) #\{)))


  Racket Users list:
  http://lists.racket-lang.org/users


Re: [racket] λ vs lambda

2012-05-14 Thread Jens Axel Søgaard
2012/5/14 Michael Rice :
> The code below (kons) gets flagged in R5RS:
>
> define: not allowed in an expression context in: (define dispatch (λ (m)
> (cond ((= m 0) x) ((= m 1) y) (else (error "Argument not 0 or 1 -- KONS"
> m)
>
> Works fine if I replace the lambda symbols with "lambda".
>
> Cause?

Insert this macro definition at the top of your R5RS code.

(define-syntax λ
  (syntax-rules ()
    ((_ . more) (lambda . more

-- 
Jens Axel Søgaard


  Racket Users list:
  http://lists.racket-lang.org/users


Re: [racket] Plot woes

2012-05-22 Thread Jens Axel Søgaard
2012/5/22 Matthias Felleisen :
> On May 22, 2012, at 8:05 AM, Neil Toronto wrote:
>
>> I've thought of such things before. Unfortunately, plot doesn't know where 
>> any
> singularities are, so it can't specifically sample the function at those 
> points. I could > probably allow the user to tell plot where they are, but I 
> can't think of a good API
> for it. I'd want something general enough to handle 1D, 2D and 3D functions,
> which allows the user to specify countably many missing values, and direction 
> of
> (dis)continuity.

It is in no way a simple matter to plot functions with singularities. Especially
not if points are not known in advance. A simple heuristic is better than none
though.

Consider the one dimensional case. Let's for the sake of argument say
that we sample the function f in two values a and b such that f(a) is
below y-min
and f(b) is over y-max.

If there is a singularity between a and b, then the points P(a,f(a))
and Q(b,f(b)) should not be connected, and if there is no singularity
(but a pretty steep ascent)
then the points should be connected.

By sampling points between a and b it ought to be possible to
give a heuristic of whether a singularity has been found or not.

Thinking aloud: Would a comparison of the rate ascent between a and b to the
mean rate of ascent of all sampled pairs of neighbors give anything usable?

If you know any references to papers and/or algorithm
on the subject, then do give a pointer. I was only able to find
this paper of Fateman:

http://www.cs.berkeley.edu/~fateman/papers/intervalplot.ps

which present a some nice examples of things to look out for.

(Just so I don't forget where I found it)
Matlab code using succesive refinement:

     http://www.stat.colostate.edu/~estep/paov/plotfuns.m

--
Jens Axel Søgaard


  Racket Users list:
  http://lists.racket-lang.org/users


[racket] Bindings for libgsl (GNU Scientific Library)

2012-05-24 Thread Jens Axel Søgaard
Hi All.

I am attempting to get Noels bindings for libgsl working on my machine
(OS X 64 bit).
https://github.com/noelwelsh/mzgsl

My problem is that it crashes DrRacket and I can't pinpoint where it happens.

I downloaded gsl using port with

sudo port install gsl

This downloaded and installed version 1.15.

Now racket is able to find and load the libraries.
I can now allocated a gsl_vector with
(gsl_vector-malloc n).

Allas calling gslvector-fill! aka gsl_vector_set_all will crash Racket.

The vector structure is defined as:

(define-cstruct _gsl_vector
  ([size   _size_t]
   [stride _size_t]
   [data   _pointer]
   [block  _pointer]
   [owner  _int]))

And the actual allocation functions as:

(define (gsl_vector-malloc n)
  (define ptr (malloc _double n 'raw))
  (define v (make-gsl_vector n 1 ptr #f 0))
  (register-finalizer v (lambda (_) (free ptr)))
  v)

Does this look right?

The actual source file is here:
https://github.com/noelwelsh/mzgsl/blob/master/low-level/gsl-vector.ss


The error message after a crash:

Process: DrRacket [62009]
Path:/Applications/Racket Full
v5.3.0.6/*/DrRacket.app/Contents/MacOS/DrRacket
Identifier:  org.racket-lang.DrRacket
Version: 5.3.0.6 (5.3.0.6)
Code Type:   X86-64 (Native)
Parent Process:  bash [62005]

Date/Time:   2012-05-24 20:56:26.374 +0200
OS Version:  Mac OS X 10.7.3 (11D50b)
Report Version:  9

Interval Since Last Report:  6884660 sec
Crashes Since Last Report:   77
Per-App Interval Since Last Report:  776847 sec
Per-App Crashes Since Last Report:   3
Anonymous UUID:  479A6BDE-6BDF-47B6-AB0F-194A795E4C53

Crashed Thread:  0  Dispatch queue: com.apple.main-thread

Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x

VM Regions Near 0:
-->
__TEXT 0001-00018000 [   32K]
r-x/rwx SM=COW  /Applications/Racket Full
v5.3.0.6/DrRacket.app/Contents/MacOS/DrRacket

Application Specific Information:
objc[62009]: garbage collection is OFF

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   libgsl.dylib0x00010d152460 gsl_vector_set_all + 
32
1   Racket  0x0001002aee5c ffi_call_unix64 + 76
2   Racket  0x0001002afa74 ffi_call + 644
3   Racket  0x0001002a1c56 ffi_do_call + 1558
4   Racket  0x000100062282 scheme_do_eval + 9058
5   Racket  0x000100064fdc
_scheme_apply_multi_from_native + 108
6   ??? 0x0001007e4078 0 + 4303241336
7   Racket  0x000100061f19 scheme_do_eval + 8185
8   Racket  0x0001000640d5 splice_execute + 229
9   Racket  0x00010006111f scheme_do_eval + 4607
10  Racket  0x000100076754 force_values + 292
11  Racket  0x000100080452
scheme_force_value_same_mark + 114
12  ??? 0x0001007cfdf7 0 + 4303158775
13  Racket  0x000100061f19 scheme_do_eval + 8185
14  Racket  0x0001000822c9
scheme_finish_apply_for_prompt + 873
15  Racket  0x00010008249c
scheme_apply_for_prompt + 92
16  Racket  0x00010008e062 call_with_prompt + 
1282
17  Racket  0x0001000650f9
_scheme_apply_multi_from_native + 393
18  ??? 0x0001037e79b0 0 + 4353587632
19  ??? 0x0001007d20fb 0 + 4303167739
20  ??? 0x0001037e657c 0 + 4353582460
21  Racket  0x000100061f19 scheme_do_eval + 8185
22  Racket  0x0001000822c9
scheme_finish_apply_for_prompt + 873
23  Racket  0x00010008249c
scheme_apply_for_prompt + 92
24  Racket  0x00010008e062 call_with_prompt + 
1282
25  Racket  0x0001000650f9
_scheme_apply_multi_from_native + 393
26  ??? 0x0001037e79b0 0 + 4353587632
27  ??? 0x0001007c5264 0 + 4303114852
28  Racket  0x000100064fdc
_scheme_apply_multi_from_native + 108
29  ??? 0x0001037e699c 0 + 4353583516
30  Racket  0x000100061f19 scheme_do_eval + 8185
31  Racket  0x000100064fdc
_scheme_apply_multi_from_native + 108
32  ??? 0x0001007cfee0 0 + 4303159008
33  Racket  0x000100061f19 scheme_do_eval + 8185
34  Racket  

Re: [racket] Bindings for libgsl (GNU Scientific Library)

2012-05-25 Thread Jens Axel Søgaard
Thanks for testing this. It was very helpful.

Using your program I got the library working on Racket 5.2.1.6 but
not on 5.3.0.6.

In mzgsl/low-level/gsl-lib.rkt I had to make sure CBLAS was loaded
in GLOBAL mode.

That is, in https://github.com/noelwelsh/mzgsl/blob/master/low-level/gsl-lib.ss
I changed

(define libgslcblas (ffi-lib cblaslibpath))

to

(define libgslcblas (ffi-lib cblaslibpath #:global? #t))

Now I get this transcript using your test program:

$ /Applications/Racket\ Full\ v5.2.1.6/bin/plt-r6rs proof.sps
#(2.0 2.0 2.0)
2.0
3.0
2.0

$ /Applications/Racket\ Full\ v5.3.0.6/bin/plt-r6rs proof.sps
Segmentation fault: 11

Note that prior to this I reinstalled GSL with this command:

sudo port install gsl +universal

whether this made any change I do not know.

/Jens Axel

  Racket Users list:
  http://lists.racket-lang.org/users


[racket] Problem with hline in

2012-05-26 Thread Jens Axel Søgaard
Hi All,

Experimenting with  slideshow/pict  I noticed that the lines
produced by hline doesn't begin and end the same way.

> (require slideshow/pict)
> (scale (hline 30 1) 15)


The start of the line is rectangular where as the end is rounded.
See attached image.

Should I change the pen type to get a line that is rounded in both ends?
If so, how?

--
Jens Axel Søgaard
<>
  Racket Users list:
  http://lists.racket-lang.org/users


Re: [racket] Problem with hline in

2012-05-26 Thread Jens Axel Søgaard
2012/5/26 Robby Findler :
> I think this is the result of cropping to the boundary box and the end
> of the line is cropped on the left, but not the right (in the
> attachment; in the program, it gets cropped along the bottom too).

That's odd. The documentation on hline says the line is centered
in its bounding box.

> This looks right:
>
> #lang racket
> (require slideshow)
> (slide (scale (hline 30 1) 15))
>
> So if you're using this in some larger context, you need to take into
> account the actual space of the line itself when cropping.

I guess I didn't knew I was cropping :-)

So when I type
(scale (hline 30 1) 15)
into the interaction window, the cropping is done by pict->bitmap?

How can I avoid the cropping?

I tried a bunch of the bounding box adjusting functions, but no cigar.

I even tried appending a blank to the left:
(hc-append (blank 1 1) (scale (hline 30 1) 30))
but that didn't work either.

/Jens Axel

  Racket Users list:
  http://lists.racket-lang.org/users


Re: [racket] Problem with hline in

2012-05-26 Thread Jens Axel Søgaard
2012/5/26 Robby Findler :
> It is possible something is wrong with hline and/or its interaction
> with scaling, I'm not sure. But this adds enough space:
>
> #lang racket
> (require slideshow/pict)
> (hc-append (blank 15 0)
>           (vc-append (scale (hline 30 1) 30)
>                      (blank 0 15))
>           (blank 15 0))

So an educated guess on how much space to add would be
the line width times the scaling?

> I wonder if something is wrong somewhere, tho, because the bounding
> box of the above appears to have some pixels of empty space on the
> top.
>
> The space on the left and right is count for the pen cap, not the line
> itself so that seems fine.
>
> As for cropping, the DrRacket REPL is the thing that does the cropping
> (and, in some cases, it may not be cropping, actually, but two
> different parts of the window are fighting with each other for the
> pixels when something draws outside of its bounding box, as a scaled
> hline does).

Okay, I thought there was a guarantee that the drawing happened
inside the bounding box.

Something is fishy with hline or my understanding of hline though.
In order to avoid using scale I tried this:

(pict->bitmap (hline (* 20 30) 20))

and got a one pixel line. See attached image.
(On version 5.3.0.6--2012-05-11 btw)

/Jens Axel
<>
  Racket Users list:
  http://lists.racket-lang.org/users


Re: [racket] Problem with hline in

2012-05-26 Thread Jens Axel Søgaard
Hi Robby,

> So maybe the easiest thing is to drop down to use 'dc' to draw the
> precise lines you want.
>
> If you spell that out here, I can probably give you some guidance on
> how to do it?

The hline is used to make a fraction.
When I scaled the fraction, I noticed the division bar was asymmetrical.

See attached file.

/Jens Axel


math-pict.rkt
Description: Binary data

  Racket Users list:
  http://lists.racket-lang.org/users


Re: [racket] Problem with hline in

2012-05-26 Thread Jens Axel Søgaard
2012/5/26 Robby Findler :
> Oh, in that case, you could do this:
>
> (hc-append (blank 1 0) (hline (- w 1) 1))

Thanks!

> If you don't want the rounded edges, you'd have to do something like this:
>
> (define (fraction p q)
>  (define w (max (pict-width p) (pict-width q)))
>  (vc-append p (vc-append (blank 0 2) (butt-hline w)) q))
>
> (require racket/gui/base)
> (define (butt-hline w)
>  (dc
>   (λ (dc dx dy)
>     (define pen (send dc get-pen))
>     (send dc set-pen (send the-pen-list find-or-create-pen
>                            (send pen get-color)
>                            (send pen get-width)
>                            'solid
>                            'butt))
>     (send dc draw-line dx dy (+ dx w) dy))
>   w 1))

I think I can use this technique to make roots.
And to make a proper "vector arrow".

Thanks,
Jens Axel


  Racket Users list:
  http://lists.racket-lang.org/users


[racket] Modifying how "interaction" renders results

2012-05-26 Thread Jens Axel Søgaard
While documenting a matrix library, I have used the nice feature
that picts returned by the evaluation are inserted into the resulting
documentation:

@interaction[#:eval matrix-eval
(current-print
 (let ([print (current-print)])
   (λ (v) (print (if (matrix? v) (matrix->pict v) v)
(matrix 2 2  1 2 3 4)]

The 2x2 matrix is converted to a pict by matrix->pict and thus
I get a nice matrix image in the documentation.

Now I am experimenting with MathJax.
Using Prabhakar Ragde code from RacketCon I can write

@$[(tex-matrix (matrix 2 3 1 2 3 4 5 6))]

and get a nice inline matrix displayed.

Then I thought, I could use the trick as before to get nice matrices
in the output:

@interaction[#:eval matrix-eval
(current-print
 (let ([print (current-print)])
   (λ (v) (print (if (matrix? v) (tex-matrix (matrix v))
(matrix 2 2  1 2 3 4)]

But tex-matrix returns an element (in the Scribble sense) and
instead of embedding the returned element into the page it
simple writes #.

Is there a way to bypass/modify how  interaction  renders the results?

--
Jens Axel Søgaard


  Racket Users list:
  http://lists.racket-lang.org/users


Re: [racket] Looping with look-behind and look-forward

2012-05-26 Thread Jens Axel Søgaard
Here is an alternative (not as efficient as MF's version).
It uses that parallel for-loops stop when one of the
sequences are empty.

#lang racket
(define (running-average-of-3-alternative l)
  (for ([x (in-list (append l '(dummy)))]
[y (in-list (cdr l))]
[z (in-list (cddr l))])
(displayln (/ (+ x y z) 3

(running-average-of-3-alternative '(1 2 3 4 5 6 7 8 9 0))
(newline)

(define (running-average-of-3 l2)
 (define-values (_1 _2)
   (for/fold ((current (second l2)) (prior (first l2))) ((next (rest
(rest l2
 (displayln (/ (+ prior current next) 3))
 (values next current)))
 (void))

(running-average-of-3 '(1 2 3 4 5 6 7 8 9 0))

2012/5/26 Ashok Bakthavathsalam :
> The line (displayln (/ (+ prior current next))) needs to be changed to
>  (displayln (/ (+ prior current next) 3))
>
> Thanks,
>
>
> On Sat, May 26, 2012 at 9:20 PM, Matthias Felleisen 
> wrote:
>>
>>
>> Do you mean that if you operated on a list it would look like this:
>>
>> #lang racket
>>
>> (define (running-average-of-3 l2)
>>  (define-values (_1 _2)
>>    (for/fold ((current (second l2)) (prior (first l2))) ((next (rest (rest
>> l2
>>      (displayln (/ (+ prior current next)))
>>      (values next current)))
>>  (void))
>>
>> (running-average-of-3 '(1 2 3 4 5 6 7 8 9 0))
>>
>>
>>
>>
>> On May 26, 2012, at 12:56 AM, Harry Spier wrote:
>>
>> > I can use for/fold to loop through a sequence while having the current
>> > element and  the previous element of the sequence still available by
>> > doing something like this.
>> >
>> > (for/fold ([previous-element-in-sequence '()][list-being-created '()])
>> >  ( [current-element-in-sequence sequence])
>> >  (do some stuff)
>> >  
>> >  (values current-element-in-sequence
>> >          (cons something list-being-created)))
>> >
>> > But what I want is to be able to loop through a sequence while having
>> > the prior, the current and the next element available.
>> >
>> > I'm sequencing through a representation of lines of a black and white
>> > page of text showing where the black pixels are and from that
>> > producing a graph showing the connectivity of the black pixel strips
>> > on each line to the ones on the lines above and below it.
>> >
>> > Using for/fold I'm able to code the graph of connectedness of the
>> > black strips on each line to the prior line in a very straightforward
>> > way, but I'd like to graph in both directions both to the prior line
>> > and to the next line at the same time.
>> >
>> > Is there a simple way to loop through a sequence and have the prior,
>> > current and next element available at the same time.
>> >
>> > Thanks,
>> > Harry
>> > 
>> >  Racket Users list:
>> >  http://lists.racket-lang.org/users
>>
>>
>> 
>>  Racket Users list:
>>  http://lists.racket-lang.org/users
>
>
>
> 
>  Racket Users list:
>  http://lists.racket-lang.org/users
>



-- 
--
Jens Axel Søgaard


  Racket Users list:
  http://lists.racket-lang.org/users


Re: [racket] Looping with look-behind and look-forward

2012-05-27 Thread Jens Axel Søgaard
It suddenly dawned on me, that the append trick is
not needed. This works too:

(define (running-average-of-3-alternative l)
 (for ([x (in-list l)]
 [y (in-list (cdr l))]
 [z (in-list (cddr l))])
   (displayln (/ (+ x y z) 3

But in this version, the list is traversed 3 times.
In the fold version it is only traversed once.

/Jens Axel


2012/5/27 Harry Spier :
> Thank you Matthias for the pattern, its exactly what I needed.
> And thank you Jens for the trick of appending a dummy element to the
> list so you don't lose the last item in the list.
> I.e.
> (define (f1 lst)
>  (define-values (result-list dummy1 dummy2)
> (for/fold ([result-list '()][prior '()] [current (first lst)])
>  [next (rest (append lst '()))]
>  
>  ...
>  (values (cons result-item result-list )
>          current
>          next))) (reverse result-list))
>
> On Sat, May 26, 2012 at 11:50 AM, Matthias Felleisen
>  wrote:
>>
>> Do you mean that if you operated on a list it would look like this:
>>
>> #lang racket
>>
>> (define (running-average-of-3 l2)
>>  (define-values (_1 _2)
>>    (for/fold ((current (second l2)) (prior (first l2))) ((next (rest (rest 
>> l2
>>      (displayln (/ (+ prior current next)))
>>      (values next current)))
>>  (void))
>>
>> (running-average-of-3 '(1 2 3 4 5 6 7 8 9 0))
>>
>>
>>
>>
>> On May 26, 2012, at 12:56 AM, Harry Spier wrote:
>>
>>> I can use for/fold to loop through a sequence while having the current
>>> element and  the previous element of the sequence still available by
>>> doing something like this.
>>>
>>> (for/fold ([previous-element-in-sequence '()][list-being-created '()])
>>>  ( [current-element-in-sequence sequence])
>>>  (do some stuff)
>>>  
>>>  (values current-element-in-sequence
>>>          (cons something list-being-created)))
>>>
>>> But what I want is to be able to loop through a sequence while having
>>> the prior, the current and the next element available.
>>>
>>> I'm sequencing through a representation of lines of a black and white
>>> page of text showing where the black pixels are and from that
>>> producing a graph showing the connectivity of the black pixel strips
>>> on each line to the ones on the lines above and below it.
>>>
>>> Using for/fold I'm able to code the graph of connectedness of the
>>> black strips on each line to the prior line in a very straightforward
>>> way, but I'd like to graph in both directions both to the prior line
>>> and to the next line at the same time.
>>>
>>> Is there a simple way to loop through a sequence and have the prior,
>>> current and next element available at the same time.
>>>
>>> Thanks,
>>> Harry
>>> 
>>>  Racket Users list:
>>>  http://lists.racket-lang.org/users
>>



-- 
--
Jens Axel Søgaard


  Racket Users list:
  http://lists.racket-lang.org/users


Re: [racket] Looping with look-behind and look-forward

2012-05-27 Thread Jens Axel Søgaard
2012/5/27 Harry Spier :
> Is the "for" form a macro?  And if so how difficult would it be to
> make a new form "for-with-look-around" that had built in look-back and
> look-ahead operators (next x) (prior x) (  next?) (prior?).
>
> So you could do something like:
>
> ((define (running-average-of-3 l)
>   (for-with-look-around
>    ([x (in-list l)])
>    (unless? (or (prior?) (next?))
>                 (displayln (/ (+ x (prior x) (next x)) 3))
>
> From a functional programming perspective is building a form like this
> a bad idea?

It is a fine idea.
Here is variation on the idea.

(define (in-triples l)
  (define (sublists xs)
(if (empty? xs)
'()
(cons xs (sublists (rest xs)
  (define (triple xs) (take xs 3))
  (sequence-map triple (drop-right (sublists l) 2)))

(define (running-average-of-3 l)
  (for ([t (in-triples l)])
(match-define (list x y z) t)
(displayln (/ (+ x y z) 3

(running-average-of-3 '(1 2 3 4 5 6))


  Racket Users list:
  http://lists.racket-lang.org/users


Re: [racket] Looping with look-behind and look-forward

2012-05-27 Thread Jens Axel Søgaard
You could consider using vectors.

#lang racket

(define (running-average-of-3-vector-edition xs)
  (define n (vector-length xs))
  (define (prev i) (vector-ref xs (- i 1)))
  (define (next i) (vector-ref xs (+ i 1)))
  (for ([(x i) (in-indexed xs)]
#:when (< 0 i (- n 1)))
(displayln (/ (+ (prev i) x (next i)) 3

(running-average-of-3-vector-edition #(1 2 3 4 5 6))


/Jens Axel




2012/5/27 Harry Spier :
> This is just a simple example to work on the form.  In my application
> I'm not processing integers, I'm processing a list of sub-lists.  Each
> sublist is of the form (number (s . e ) ...)
>
> On Sun, May 27, 2012 at 12:16 PM, Richard Cleis  wrote:
>> If you are only using integers, efficiency matters, and your running 
>> averages are larger than two (I can't tell of you are using three for a 
>> simple example, or if that is the only requirement), then it might be better 
>> to maintain the latest sum by subtracting the oldest member and adding the 
>> newest. If the processing time for the arithmetic is much smaller than the 
>> overhead of list maintenance, then this post isn't very useful.
>>
>> rac
>>
>>
>> On May 27, 2012, at 9:54 AM, Harry Spier wrote:
>>
>>> Sorry Jens, I see I've just recreated the form you originally suggested.
>>> Thanks, Harry
>>>
>>> On Sun, May 27, 2012 at 11:46 AM, Harry Spier  
>>> wrote:
>>>> I think I've come up with a simpler form to do this.
>>>>
>>>> (define (running-average-of-3 l)
>>>>   (for
>>>>    ( [prior (in-list l)]
>>>>      [x (in-list (rest l))]
>>>>      [next (in-list (rest (rest l)))])
>>>>   (displayln (/ (+ x prior next) 3
>>>>
>>>> (running-average-of-3 '(1 2 3 4 5 6))
>>>>
>>>>
>>>> So I can do something like:
>>>>
>>>> (define (f1 l)
>>>>   (for/fold ([result-list '()])
>>>>    ( [prior (in-list (append '() l))]
>>>>      [x (in-list l)]
>>>>      [next (in-list  (append (rest l) '()))])
>>>>    ...
>>>>    ... make new-result-element using x prior and next...
>>>>   (cons new-result-element result-list))
>>>>  (reverse result-list))
>>>>
>>>> The list I'm working on in my application has about 40,000 sub-lists.
>>>> Will the compiler build new lists from scratch as the sequence for
>>>> prior and next in this code or will it use pointers to and from the
>>>> existing list l to do this?
>>>>
>>>> Thanks,
>>>> Harry
>>>>
>>>> On Sun, May 27, 2012 at 10:38 AM, Jens Axel Søgaard
>>>>  wrote:
>>>>> 2012/5/27 Harry Spier :
>>>>>> Is the "for" form a macro?  And if so how difficult would it be to
>>>>>> make a new form "for-with-look-around" that had built in look-back and
>>>>>> look-ahead operators (next x) (prior x) (  next?) (prior?).
>>>>>>
>>>>>> So you could do something like:
>>>>>>
>>>>>> ((define (running-average-of-3 l)
>>>>>>   (for-with-look-around
>>>>>>    ([x (in-list l)])
>>>>>>    (unless? (or (prior?) (next?))
>>>>>>                 (displayln (/ (+ x (prior x) (next x)) 3))
>>>>>>
>>>>>> From a functional programming perspective is building a form like this
>>>>>> a bad idea?
>>>>>
>>>>> It is a fine idea.
>>>>> Here is variation on the idea.
>>>>>
>>>>> (define (in-triples l)
>>>>>  (define (sublists xs)
>>>>>    (if (empty? xs)
>>>>>        '()
>>>>>        (cons xs (sublists (rest xs)
>>>>>  (define (triple xs) (take xs 3))
>>>>>  (sequence-map triple (drop-right (sublists l) 2)))
>>>>>
>>>>> (define (running-average-of-3 l)
>>>>>  (for ([t (in-triples l)])
>>>>>    (match-define (list x y z) t)
>>>>>    (displayln (/ (+ x y z) 3
>>>>>
>>>>> (running-average-of-3 '(1 2 3 4 5 6))
>>>
>>> 
>>>  Racket Users list:
>>>  http://lists.racket-lang.org/users
>>



-- 
--
Jens Axel Søgaard


  Racket Users list:
  http://lists.racket-lang.org/users


Re: [racket] Help with filter-map

2012-05-28 Thread Jens Axel Søgaard
2012/5/28 Joe Gilray :
> I created some Racket solutions to ProjectEuler #71.  Below is one that uses
> filter and map:
>
> (define (euler71c)
>   (numerator (apply max (filter (λ (n) (> (/ 3 7) n)) (map (λ (n) (/ (floor
> (/ (* n 3) 7)) n)) (stream->list (in-range 2 100)))
>
> 1) I thought I might speed it up by using filter-map, but I cannot
> understand how to do it.  I read the 1 line I could find in the reference
> and it just doesn't help me

The function filter-map keeps non-false elements.
The idiom is therefore to use (and (> /37 n) n).
The for and returns the last element only if all the preceding tests were true.

> 2) The code above takes about 4x the time of a simple for loop
> implementation.  What can I do to speed it up?

Avoid allocation of unnecessary intermediate lists.
Most often fold can be used for this purpose.

Btw - when benchmarking in DrRacket - turn of debugging.

I tried a few things. The results were:

cpu time: 5174 real time: 5430 gc time: 3368
cpu time: 4628 real time: 4859 gc time: 3311
cpu time: 4122 real time: 4288 gc time: 2952
cpu time: 3295 real time: 3401 gc time: 2318
cpu time: 2674 real time: 2721 gc time: 1861
cpu time: 2699 real time: 2746 gc time: 1843

/Jens Axel


#lang racket

(define end 100)

(define (euler71c)
  (numerator
   (apply max
  (filter (λ (n) (> 3/7 n))
  (map (λ (n) (/ (floor (/ (* n 3) 7)) n))
   (stream->list (in-range 2 end)))

(define (euler71d)
  (numerator
   (apply max
  (filter (λ (n) (> 3/7 n))
  (map (λ (n) (/ (floor (/ (* n 3) 7)) n))
   (range 2 end))

(define (euler71e)
  (numerator
   (apply max
  (filter-map
   (λ (m)
 (define n (/ (floor (/ (* m 3) 7)) m))
 (and (> 3/7 n) n))
   (range 2 end)

(define (euler71f)
  (numerator
   (foldl (λ (m max-so-far)
(define n (/ (floor (/ (* m 3) 7)) m))
(if (> 3/7 n)
(max n max-so-far)
max-so-far))
  0
  (range 2 end

(define (euler71g)
  (numerator
   (for/fold ([max-so-far 0]) ([m (in-range 2 end)])
 (define n (/ (floor (/ (* m 3) 7)) m))
 (if (> 3/7 n) (max n max-so-far) max-so-far

(define (euler71h)
  (define max-so-far 0)
  (for ([m (in-range 2 end)])
(define n (/ (floor (/ (* m 3) 7)) m))
(set! max-so-far
  (if (> 3/7 n) (max n max-so-far) max-so-far)))
  (numerator max-so-far))

(define (test)
  (let ([old-end end])
(set! end 10)
(begin0
  (list (equal? (euler71c) (euler71d))
(equal? (euler71d) (euler71e))
(equal? (euler71e) (euler71f))
(equal? (euler71f) (euler71g))
(equal? (euler71g) (euler71h)))
  (set! end old-end

(define (benchmark-one f)
  (collect-garbage)
  (time (begin (f) (void

(define (benchmark)
  (benchmark-one euler71c)
  (benchmark-one euler71d)
  (benchmark-one euler71e)
  (benchmark-one euler71f)
  (benchmark-one euler71g)
  (benchmark-one euler71h))


  Racket Users list:
  http://lists.racket-lang.org/users


Re: [racket] Plot woes

2012-05-30 Thread Jens Axel Søgaard
Hi All,

Attached is my version of a 2d-plotter that handles singularities.
Give it a spin with your favorite ill-behaved functions and
report back with ones badly handled.

/Jens Axel


adaptive-plotting.rkt
Description: Binary data

  Racket Users list:
  http://lists.racket-lang.org/users


Re: [racket] FFI Pass/Return By Value

2012-06-05 Thread Jens Axel Søgaard
I am not 100% sure this is the correct reason for the segmentation fault,
but is worth examining.

Even though it is perfectly legal C to return structs as values, there
seems to be more than one way of implementing it. This is in turn
implies that one must compile the library in question with options
that works with what ffilib expects.

More detail from http://www.delorie.com/gnu/docs/gcc/gcc_121.html:

---

When compiling functions that return structures or unions, GCC output
code normally uses a method different from that used on most versions
of Unix. As a result, code compiled with GCC cannot call a
structure-returning function compiled with PCC, and vice versa.
The method used by GCC is as follows: a structure or union which is 1,
2, 4 or 8 bytes long is returned like a scalar. A structure or union
with any other size is stored into an address supplied by the caller
(usually in a special, fixed register, but on some machines it is
passed on the stack). The machine-description macros STRUCT_VALUE and
STRUCT_INCOMING_VALUE tell GCC where to pass this address.

By contrast, PCC on most target machines returns structures and unions
of any size by copying the data into an area of static storage, and
then returning the address of that storage as if it were a pointer
value. The caller must copy the data from that memory area to the
place where the value is wanted. GCC does not use this method because
it is slower and nonreentrant.

On some newer machines, PCC uses a reentrant convention for all
structure and union returning. GCC on most of these machines uses a
compatible convention when returning structures and unions in memory,
but still returns small structures and unions in registers.

You can tell GCC to use a compatible convention for all structure and
union returning with the option `-fpcc-struct-return'.

---

See also the answer by tonylo at:
http://stackoverflow.com/questions/161788/are-there-any-downsides-to-passing-structs-by-value-in-c-rather-than-passing-a

/Jens Axel


2012/6/5 Vince Kuyatt :
> I am having a strange issue to do with making an FFI binding to some
> simple C functions which immediately result in a segmentation fault.
> In these functions, all arguments are pass by value, and all return
> values are values, not pointers. I am wondering if there is an issue
> with the FFI that getting a struct as a return value is causing some
> issues, or passing a cstruct by value. I can think of no other reason
> that this could be happening.
>
> For example, I have the simple definition in Racket:
> (define cpv
>   (get-ffi-obj "_cpv" chipmunk (_fun _cpFloat _cpFloat -> _cpVect)))
>
> where chipmunk is a binding to a valid ffi-lib. This corresponds to
> the C function:
>
> static inline cpVect cpv(const cpFloat x, const cpFloat y)
> {
>         cpVect v = {x, y};
>         return v;
> }
>
> Calling cpv in Racket at any point will immediately cause a
> segmentation fault. Is my theory about why this is happening correct?
> Or is there something else going on that I am unaware of? I realize
> this is a small function that could easily be re-defined in Racket
> (the current FFI bindings to Chipmunk do this, actually, possibly
> because the developer ran into the same issue I am), but it seems
> important to know why this is happening so as to avoid it in the
> future either with this FFI binding, or any others I might put
> together.
>
> 
>  Racket Users list:
>  http://lists.racket-lang.org/users



-- 
--
Jens Axel Søgaard


  Racket Users list:
  http://lists.racket-lang.org/users


[racket] Definitions in cond-bodies

2012-06-08 Thread Jens Axel Søgaard
I have found an interesting program:

#lang racket
(let ([x 1])
 (cond
   [(= x 1)
    (define u 2)
    (+ u 1)]
   [else u]))

When run gives a very reasonable error message:
    expand: unbound identifier in module in: u

When

(let ([x 1])
 (cond
   [(= x 1)
    (define u 2)
    (+ u 1)]
   [else u]))

is pasted into the interaction window, I get 3  !

I was expecting an error.


Welcome to DrRacket, version 5.3.0.6--2012-05-11(9401a53/a) [3m].
Language: racket; memory limit: 128 MB.
. expand: unbound identifier in module in: u
> (let ([x 1])
 (cond
   [(= x 1)
    (define u 2)
    (+ u 1)]
   [else u]))
3


  Racket Users list:
  http://lists.racket-lang.org/users


Re: [racket] Definitions in cond-bodies

2012-06-08 Thread Jens Axel Søgaard
2012/6/8 Sam Tobin-Hochstadt :

> What's happening is that `#%top` behaves differently at the REPL than
> in a module.  This enables you to write:
>
> -> (define (even? x) (or (zero? x) (odd? (sub1 x
> -> (define (odd? x) (or (= x 1) (even? (sub1 x
>
> without getting an error when entering the first line.

Ah!

Thanks,
Jens Axel


  Racket Users list:
  http://lists.racket-lang.org/users


Re: [racket] WeScheme cond branch error

2012-06-10 Thread Jens Axel Søgaard
Use local for internal definitions in the teaching languages.

http://docs.racket-lang.org/htdp-langs/advanced.html?q=local#(form._((lib._lang/htdp-advanced..rkt)._local))

/Jens Axel



2012/6/10 Ashok Bakthavathsalam :
> Although the following code works perfectly well in DrRacket environment, it
> generates the following error in WeScheme:
>   Inside a cond branch, I expect to see a question and an answer, but I see
> more than two things here.
>
>      at: line 15, column 4, in 
>
>
> How do I fix this? The actual code is available
> at http://www.wescheme.org/view?publicId=gutsy-buddy-woken-smoke-wrest
>
> (define (insert l n e)
>   (if (= 0 n)
>       (cons e l)
>       (cons (car l)
>             (insert (cdr l) (- n 1) e
>
> (define (seq start end)
>   (if (= start end)
>       (list end)
>       (cons start (seq (+ start 1) end
>
> (define (permute l)
>   (cond
>     [(null? l) '(())]
>     [else (define (silly1 p)
>             (define (silly2 n) (insert p n (car l)))
>             (map silly2 (seq 0 (length p
>             (apply append (map silly1 (permute (cdr l]))
>
>
>
>
>
>
> 
>  Racket Users list:
>  http://lists.racket-lang.org/users
>



-- 
--
Jens Axel Søgaard


  Racket Users list:
  http://lists.racket-lang.org/users


[racket] Opacity of borders in slideshow/pict

2012-06-10 Thread Jens Axel Søgaard
It seems the "borders" of disks and filled ellipses doesn't respect
the opacity given by cellophane.

This draws an yellow disk overlapping a gren disc.
The opacity of the border of the disk is different than
the interior.

Is this the intended behaviour?
If so how can set the opacity of the border?

/Jens Axel


#lang racket
(require slideshow/pict
 racket/draw)

(define (find-color color-symbol)
(let ([color-name
   (string-downcase
(symbol->string color-symbol))])
  (send the-color-database find-color color-name)))

(pin-over (colorize (disk 50) (find-color 'green))
  25 0
  (cellophane
   (colorize (disk 50) (find-color 'yellow)) 0.7))
<>
  Racket Users list:
  http://lists.racket-lang.org/users


Re: [racket] Opacity of borders in slideshow/pict

2012-06-10 Thread Jens Axel Søgaard
2012/6/10 Robby Findler :
> I think it does, actually. What's happening is that it is drawing the
> interior with the specified alpha value and then drawing the border
> with the specified alpha, which means that pixels near the border are
> drawn twice and so appear twice as dark.
>
> I've just pushed a change so that you can pass the #:draw-border?
> argument to disk and filled-ellipse to avoid drawing the border.

Great.

Thanks,
Jens Axel

  Racket Users list:
  http://lists.racket-lang.org/users


Re: [racket] Opacity of borders in slideshow/pict

2012-06-10 Thread Jens Axel Søgaard
Thanks.  I didn't connect the dots, that the linewidth
of the current pen was used as the border size.
On GitHub I have added a line in the documentation.

/Jens Axel


2012/6/10 Matthew Flatt :
> FWIW, another way to do that is
>
>  (linewidth #f (disk 50))
>
> At Sun, 10 Jun 2012 19:10:39 +0200, Jens Axel Søgaard wrote:
>> 2012/6/10 Robby Findler :
>> > I think it does, actually. What's happening is that it is drawing the
>> > interior with the specified alpha value and then drawing the border
>> > with the specified alpha, which means that pixels near the border are
>> > drawn twice and so appear twice as dark.
>> >
>> > I've just pushed a change so that you can pass the #:draw-border?
>> > argument to disk and filled-ellipse to avoid drawing the border.
>>
>> Great.
>>
>> Thanks,
>> Jens Axel
>> 
>>   Racket Users list:
>>   http://lists.racket-lang.org/users



-- 
--
Jens Axel Søgaard


  Racket Users list:
  http://lists.racket-lang.org/users


[racket] Problem with "Populate compiled directories" and submodules

2012-06-20 Thread Jens Axel Søgaard
Hi All,

I have a problem which I am unsure how to solve.

I might have a bug in my own code, but since submodules
are new, maybe it is related to the recent changes.

The problems is this:
   - I have implemented a new #lang langauge called bracket
   - programs beginning with #lang bracket runs fine
 in DrRacket *if*  "Populate compiled directories"  is turned off.
The exact error message is as follows:

require: unknown module
  module name: #
Module Language: invalid language specification in:
#

The file in the error message
"/Users/soegaard/Dropbox/GitHub/bracket/bracket/bracket.rkt" exists,
and it contains a submodule called expression.

The backtrace begins with:
#: #f:#f
/Applications/Racket Full
v5.3.0.11/collects/errortrace/errortrace-lib.rkt: 434:2

This is with DrRacket, version 5.3.0.11--2012-06-15(4eb0d3d/a) [3m].

The code is available here:
 https://github.com/soegaard/bracket

In the terminal use
   raco link bracket to register the bracket language.


/Jens Axel

  Racket Users list:
  http://lists.racket-lang.org/users


Re: [racket] Problem with "Populate compiled directories" and submodules

2012-06-20 Thread Jens Axel Søgaard
2012/6/20 Asumu Takikawa :
> On 2012-06-20 19:39:46 +0200, Jens Axel Søgaard wrote:
>> This is with DrRacket, version 5.3.0.11--2012-06-15(4eb0d3d/a) [3m].
>
> I tried running the file `bracket/bracket/tests/testing.rkt` in
> 5.3.0.12--2012-06-19 and it appeared to work for me. I just had
> `bracket/bracket` linked with raco.
>
> Is there any particular test file I should try running to reproduce your
> error?

Yes. `bracket/bracket/tests/testing.rkt` has the problem
and so does bracket/bracket-lang.rkt .

I run it with the options:
  Debugging
  Population
  Preserve Stacktrace
in pane with dynamic options.

> As a side note, I like the idea of building a CAS using Racket.

So do I :-)

/Jens Axel


  Racket Users list:
  http://lists.racket-lang.org/users


[racket] How to associate a custom syntax color lexer with a new module language

2012-06-22 Thread Jens Axel Søgaard
Hi All,

I have implemented a #lang language called bracket.
The language is installed as a collection with the raco link command.

soegaard$ /Applications/Racket\ Full\ v5.3.0.11/bin/raco link -l
User links:
 collection: "bracket"  path: "/Users/soegaard/Dropbox/GitHub/bracket/bracket"
Installation links:
soegaard$

To get proper source coloring in DrRacket, I have implemented a color-lexer.
From the documentation I see that to tell DrRacket about the color-lexer,
one must in the reader associated with the language make a get-info function.

This I have done as follows (the definitions of bracket-read and
bracket-read-syntax
are left out).

However it seems that DrRacket never calls the get-info function in question.
To check this, I added a displayln call to print a message each get-info
is called, and I never see any output from this.

Is there something else that needs to be done in order to get the color-lexer
to DrRacket? Although I have read the manual several times, I might
have missed something obvious.

The reader, parser and other related files are available here:
https://github.com/soegaard/bracket/tree/master/bracket/lang

A working test file with a program written in Bracket is here:
https://github.com/soegaard/bracket/blob/master/bracket/tests/testing.rkt


Excerpt from bracket/lang/reader.rkt :
#lang racket
(provide (rename-out [bracket-read read]
   [bracket-read-syntax read-syntax])
  get-info)

(require "parser.rkt")

(define (get-info in mod line col pos)
  (displayln (list 'reader/get-info in mod line col pos))
  (lambda (key default)
(displayln (list  'reader/get-info  key default))
(case key
  [(color-lexer)
   (dynamic-require 'bracket/lang/parser 'color-lexer)]
  [else default])))

--
Jens Axel Søgaard


  Racket Users list:
  http://lists.racket-lang.org/users


Re: [racket] How to associate a custom syntax color lexer with a new module language

2012-06-22 Thread Jens Axel Søgaard
Hi Danny,

2012/6/22 Danny Yoo :
>> However it seems that DrRacket never calls the get-info function in question.
>> To check this, I added a displayln call to print a message each get-info
>> is called, and I never see any output from this.
>
> Odd; I'm seeing output!  So I can't duplicate what you're seeing:
> DrRacket appears to be running the get-info function on my end.

Hmm. Odd indeed. What version do you use?
From the output below it looks like 5.2.1, but that can't be right,
since submodules were introduced later.

Thanks for trying this.

/Jens Axel


>
> Here's what I'm seeing on the console when I try running on one of
> your test files "testing.rkt":
>
> ---
> kepler ~/work/bracket/bracket/lang $ drracket ../tests/testing.rkt
> (reader/get-info # bracket/lang/reader #f #f 1)
> (reader/get-info drracket:toolbar-buttons #f)
> (reader/get-info drscheme:toolbar-buttons #f)
> (reader/get-info drracket:opt-out-toolbar-buttons ())
> (reader/get-info # bracket/lang/reader #f #f 1)
> close
> close
> (reader/get-info # bracket/lang/reader #f #f 1)
> (reader/get-info # bracket/lang/reader 1 0 1)
> (reader/get-info color-lexer #f)
> exception in colorer thread: #(struct:exn:fail:contract:arity "context
> expected 1 value, received 5 values: \"\\n\" 'white-space #f
> # #" #)
>
>  === context ===
> /home/dyoo/local/racket-5.2.1/lib/racket/collects/syntax-color/module-lexer.rkt:25:0:
> module-lexer
> /home/dyoo/local/racket-5.2.1/lib/racket/collects/framework/private/racket.rkt:1281:26
> /home/dyoo/local/racket-5.2.1/lib/racket/collects/framework/private/color.rkt:292:4:
> re-tokenize method in ...rk/private/color.rkt:66:2
> /home/dyoo/local/racket-5.2.1/lib/racket/collects/framework/private/color.rkt:455:17


  Racket Users list:
  http://lists.racket-lang.org/users


Re: [racket] How to associate a custom syntax color lexer with a new module language

2012-06-22 Thread Jens Axel Søgaard
That might be it. I thought that the get-info business avoided
the need of an info.rkt file.

Thanks,
Jens Axel


2012/6/22 Robby Findler :
> One thing that's easy to forget is to re-run 'raco setup' to register
> the info.rkt's keys.
>
> Robby
>
> On Fri, Jun 22, 2012 at 9:08 AM, Danny Yoo  wrote:
>>> However it seems that DrRacket never calls the get-info function in 
>>> question.
>>> To check this, I added a displayln call to print a message each get-info
>>> is called, and I never see any output from this.
>>
>> Odd; I'm seeing output!  So I can't duplicate what you're seeing:
>> DrRacket appears to be running the get-info function on my end.
>>
>> Here's what I'm seeing on the console when I try running on one of
>> your test files "testing.rkt":
>>
>> ---
>> kepler ~/work/bracket/bracket/lang $ drracket ../tests/testing.rkt
>> (reader/get-info # bracket/lang/reader #f #f 1)
>> (reader/get-info drracket:toolbar-buttons #f)
>> (reader/get-info drscheme:toolbar-buttons #f)
>> (reader/get-info drracket:opt-out-toolbar-buttons ())
>> (reader/get-info # bracket/lang/reader #f #f 1)
>> close
>> close
>> (reader/get-info # bracket/lang/reader #f #f 1)
>> (reader/get-info # bracket/lang/reader 1 0 1)
>> (reader/get-info color-lexer #f)
>> exception in colorer thread: #(struct:exn:fail:contract:arity "context
>> expected 1 value, received 5 values: \"\\n\" 'white-space #f
>> # #" #)
>>
>>  === context ===
>> /home/dyoo/local/racket-5.2.1/lib/racket/collects/syntax-color/module-lexer.rkt:25:0:
>> module-lexer
>> /home/dyoo/local/racket-5.2.1/lib/racket/collects/framework/private/racket.rkt:1281:26
>> /home/dyoo/local/racket-5.2.1/lib/racket/collects/framework/private/color.rkt:292:4:
>> re-tokenize method in ...rk/private/color.rkt:66:2
>> /home/dyoo/local/racket-5.2.1/lib/racket/collects/framework/private/color.rkt:455:17
>> 
>>  Racket Users list:
>>  http://lists.racket-lang.org/users



-- 
--
Jens Axel Søgaard


  Racket Users list:
  http://lists.racket-lang.org/users


Re: [racket] How to associate a custom syntax color lexer with a new module language

2012-06-22 Thread Jens Axel Søgaard
2012/6/22 Robby Findler :
> Oh, duh. You're right of course.
>
> FWIW, DrRacket calls read-language on a port containing the contents
> of the definitions window. Probably the call you're interested in is
> in drracket/private/module-language-tools.rkt. If you see exceptions
> being swallowed there, then probably I coudl add some logging code to
> help others avoid these problems in the future.

That might help. If it is a wrong-path problem, then it would
be useful to see the path in question.

I am seeing some strange submodule/expansion errors, so
perhaps something is broken in my installation?
Although I downloaded the latest pre-prerelease the other day,
I think I'll try compiling from source (just in case).

Thanks,
Jens Axel

  Racket Users list:
  http://lists.racket-lang.org/users


  1   2   3   4   5   6   7   8   >