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_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: 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] 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 (λ (s)
>>>  (string->symbol
>>> 

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

2021-10-31 Thread Jens Axel Søgaard
gt;>>> 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_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_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_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] 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] 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] 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_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] 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] 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] 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_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] 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] 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] 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] 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_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_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] 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] 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] 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] 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] 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] 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-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] Linear algebra performance (was: calculations with arrays)

2020-11-24 Thread Jens Axel Søgaard
Den tir. 24. nov. 2020 kl. 15.12 skrev Dominik Pantůček <
dominik.pantu...@trustica.cz>:

> Hello,
>
> > If you are after numerical calculations for mxn matrices, then look at
> > `flomat`
> > which uses the same underlying C/Fortran library that NumPy uses.
> >
> > https://docs.racket-lang.org/manual-flomat/index.html
> >
> > If you need rrays with more dimensions than 2 use `math/array`.
> >
> > If you need simple computation of 1-dimensional data, you can use
> > standard Racket vectors (or flomats or arrays).
>
> I didn't know about `flomat'. Thanks for (yet another) good hint.
>
> However, for my project I needed really fast matrix multiplication (and
> other basic linear algebra functions). It turned out that most of the
> available options are sub-optimal at best. To my surprise `flomat` is
> one of those.
>
> Mostly I am concerned with 3D and 4D matrices and vectors.
>
> During the past few months I hacked together a fairly optimized
> module[1] for performing these operations that defines algebras for
> given dimension during macro expansion stage and all the procedures are
> constructed in a way that helps Racket (mainly CS) perform all
> operations unboxed.
>
> In the repository, there is a benchmark script, which yields the
> following (self-explanatory) results:
>
>  Welcome to Racket v7.9.0.5 [cs].
>
...

> What puzzles me the most: when I read `flomat' documentation, I thought
> it must beat my implementation by far margin - it's a native code for
> really basic number crunching. When using the `times!' variant of matrix
> multiplication, I would expect it to outperform anything implemented in
> in pure Racket.
>
> Is there something I miss or is it really the case, that carefully
> crafted Racket implementation is the fastest option right now?
>

I think the main reason that flomat matrices are slower than your flalgebra
ones
is the cost of the FFI call. The cost of calling a C foreign function
doesn't
depend on the size of the matrix though - so for large matrices the cost
is negligible. However for small matrices, it is faster to stay in the
Racket world.

I believe game libraries in C also implement their own 3x3 matrices rather
than using BLAS/LAPACK. BLAS can handle very large matrices and
makes an effort to give good results even for ill-conditioned matrices.


> I actually wanted to write a similar email some time ago - in the spring
> - about the typed math/matrix variant. But I was almost certain I am
> doing something wrong and should figure it out. Now I am more and more
> convinced that the performance of all number crunching libraries - as
> they can be used in Racket - might be the real issue here.
>

I have somewhat regretted that the matrices in math/matrix used math/array
arrays to represent matrices directly. A traditional approach would have
been
better. However math/matrix matrices are more general - they also work
when you need matrices over exact integers or over rationals.

In order from slowest to fastest (when used for floats over 3x3 matrices):

   math/matrix   (most general, very slow)
   flomat(only floats, arbitrary size)
   flagebra (floats, square only?)

To satisfy my curiosity, of the performance of flomat:

One way to get a little extra performance out of  flomat! is to use times!
instead of times. This avoids the repeated allocation. The code of times!
is:
[image: image.png]

For a more direct call to the C multiplication routine:

[image: image.png]
So `(flomat! A B C)` will compute A*B and store it in C.

Maybe there is a specialized A*B only routine in BLAS that
can be used instead?


The benchmarks suggest that the  `times` in flomat can be improved for
smaller matrices by calling specialized routines written in Racket.

If you (or anyone else) are interested in improving `flomat` for multiplying
smaller matrices, I would be glad to receive patches.

Btw - you have some fancy tricks in `flalgebra.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/CABefVgxaLO%2Bz%2BHm04iMFu5nrTPFH8KkusCGoSNyHH%3D_bdT3L9A%40mail.gmail.com.


Re: [racket-users] calculations with arrays

2020-11-18 Thread Jens Axel Søgaard
Den ons. 18. nov. 2020 kl. 14.15 skrev Tim Meehan :

> Is there a way to use Racket vectors similarly to how one might use NumPy?
> (Or are vectors even the right thing to use?)
>

If you are after numerical calculations for mxn matrices, then look at
`flomat`
which uses the same underlying C/Fortran library that NumPy uses.

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

If you need rrays with more dimensions than 2 use `math/array`.

If you need simple computation of 1-dimensional data, you can use
standard Racket vectors (or flomats or arrays).

/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/CABefVgxpKzJQj2HuSNDhYVrBPy2E%2BhUW7u4b%2BeC%2BkJhc4JoC9Q%40mail.gmail.com.


Re: [racket-users] Package Server Update Status

2020-08-18 Thread Jens Axel Søgaard
Den tir. 18. aug. 2020 kl. 16.57 skrev Deren Dohoda :

> Hi team,
>
> I notice on the very nice about page,
> https://pkg-build.racket-lang.org/about.html, it does not give an
> indication of when packages are rebuilt. I had a package that had doc
> problems and conflicts that I resolved (the ol' manual.scrbl curse). It
> appeared from me browsing information on a few packages that things were
> rebuilt approximately once per week but it has now been over a week. The
> status seems to indicate that a fresh package was noticed on my repository
> but it hasn't been reflected in the build.
>
> Is there a problem with the server at the moment or am I simply being
> impatient?
>

Been there.

Is it possible to send a "your package has now been built" email, to those
authors
that recently clicked the "scan my packages" button?

/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/CABefVgz3-SZKD4Gzp-9vw3YNQRtcp_KgMWye6oORHsKW0Vi9%2BQ%40mail.gmail.com.


Re: [racket-users] [racket users] %app question

2020-08-13 Thread Jens Axel Søgaard
Den tor. 13. aug. 2020 kl. 21.55 skrev Kevin Forchione :

> Hi guys,
>
> Pollen makes use of something like this:
>
> (require syntax/parse/define)
>
> (define-simple-macro (#%top . x) 'x)
>
>
> and it comes in handy in some of my projects. But I’m wondering if there’s
> an equivalent for redirecting an application that hasn’t been defined?
>
> In other words, if foo is not a procedure then (foo 1 2 3) would redirect
> to (do-this foo 1 2 3) where do-this is defined?
>
> Any help is appreciated.
>

Hi Kevin,

In Bracket [1] used your idea to produce s-expression, if the first argument
of #%app isn't a function:

; In the BRACKET language an application of
  ; a non-function evaluates to an expression.
  (define-syntax (sym-app stx)
(syntax-case stx ()
  [(_ op arg ...)
   (quasisyntax/loc stx
 (let ([o op])
   (if (procedure? o)
   #,(syntax/loc stx (#%app o arg ...))
   (if (holdable? o)
   (cons o '(arg ...))
   (cons o (list arg ...))]))

There is an additional wrinkle - if a function is "holdable" it "holds"
(postpones) the
evaluation of its arguments. This can simply we be removed, if you don't
need it.

More details here:

https://github.com/soegaard/bracket/blob/master/bracket/bracket.rkt#L80


/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/CABefVgxOx-v%2BZTMGB2tzxmrvb0PamAs4J%3Dg0ovBMTJT8D1bosw%40mail.gmail.com.


Re: [racket-users] macro hiding in raco expand

2020-08-10 Thread Jens Axel Søgaard
   (#%app
>   (lambda (e)
> (if (#%app stx-pair? e)
>   (#%app
>cons/#f
>(#%app stx-car e)
>(#%app
> (lambda (e)
>   (if (#%app stx-pair? e)
> (let-values (((mh) (#%app stx-car
> e)))
>   (if mh
> (if (#%app
>  stx-null/#f
>  (#%app stx-cdr e))
>   mh
>   '#f)
> '#f))
> '#f))
> (#%app stx-cdr e)))
>   '#f))
>   (#%app stx-cdr e))
>  '#f)
>'#f))
>arg)))
>   (if rslt
> (let-values (((sc1) (#%app unsafe-car rslt))
>  ((sc2) (#%app unsafe-cdr rslt)))
>   (let-values ()
> (#%app
>  syntax-protect
>  (let-values (((loc) (#%app check-loc 'syntax/loc
> user-stx)))
>(#%app
> t-subst
> loc
> (quote-syntax (let _ (set! _ _) (set! _ tmp)))
> '(1 recur 2 recur 3)
> (#%app
>  t-resyntax
>  '#f
>  (quote-syntax STX)
>  (#%app
>   t-list
>   (#%app t-subst '#f (quote-syntax (tmp _)) '(1) sc1)))
> (#%app list '(1 2) sc1 sc2)
> (#%app list '(1) sc2))
> (let-values (((rslt) (#%app (lambda (e) null) arg)))
>   (if rslt
> (let-values ()
>   (let-values () (#%app pattern-failure user-stx '(x y
> (#%app raise-syntax-error '#f '"bad syntax" arg
>(define-values (a) '10)
>(define-values (b) '20)
>(#%app
> call-with-values
> (lambda () (let-values (((tmp) a)) (set! a b) (set! b tmp)))
> print-values)))
>
> --
> 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/94E20736-F1F7-4073-B3FA-505ADD71DB4F%40dcc.uchile.cl
> <https://groups.google.com/d/msgid/racket-users/94E20736-F1F7-4073-B3FA-505ADD71DB4F%40dcc.uchile.cl?utm_medium=email_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/CABefVgxMiOCUJkBwJhXOMzFu5gRaK%2BfefE-gkvSfXSkiuMT4vw%40mail.gmail.com.


Re: [racket-users] namespaces + eval + reader

2020-07-31 Thread Jens Axel Søgaard
Den fre. 31. jul. 2020 kl. 04.01 skrev Shriram Krishnamurthi <
shri...@gmail.com>:

>  want to create a namespace for (say) the BSL language in DrRacket.
> Critically, I need the *reader* to be aligned with this language.
> Otherwise, small semantic discrepancies creep in.

...

> The expressions being `eval`ed are coming from a file, via `read`. I have
> the freedom to change things there.
>
I think you can use the htdp-reader directly:

https://github.com/racket/htdp/blob/master/htdp-lib/lang/htdp-reader.rkt

If not, you can at least see how the reader is configured in lines 46-48:

[read-case-sensitive (lookup 'read-case-sensitive table)]
[read-decimal-as-inexact #f]
[read-accept-dot #f] /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/CABefVgwg%3DkeRRQM2W9PDHXCvgcFneuquXuqnvyqa5BqaG0Zbpg%40mail.gmail.com.


Re: [racket-users] combining require, build-path, and namespaces

2020-07-21 Thread Jens Axel Søgaard
Den tir. 21. jul. 2020 kl. 20.25 skrev Sorawee Porncharoenwase <
sorawee.pw...@gmail.com>:

> This is weird. I usually parameterize current-namespace when using
> namespace-* functions, and in this particular case it works fine.
>
> On Tue, Jul 21, 2020 at 11:05 AM Shriram Krishnamurthi 
> wrote:
>
>> Thank you! Would you know why I might get this error:
>>
>> ; require: unknown module
>>
>> ;   module name:
>>
>> ; #>
>>
>> (This is from inside a module.)
>>
>> Trying the same at the REPL, I see the same thing:
>>
>> > (define n (make-base-namespace))
>>
>> > (namespace-require `(file ,(path->string (build-path "wheats"
>> "w1.rkt"
>>
>> [note no optional namespace]
>> works fine; the name is available at the top-level; but using the same
>> pathname but with the namespace parameter:
>>
>> > (namespace-require `(file ,(path->string (build-path "wheats"
>> "w1.rkt"))) n)
>>
>> ; require: unknown module
>>
>> ;   module name:
>>
>> ; #>
>>
>> (The file in question begins with #lang racket.)
>>
>>

#lang racket

(define ns (make-base-namespace))
(define p  (build-path "/Users/soegaard/tmp" "w1.rkt"))

(parameterize ([current-namespace ns])
  (namespace-require p))

I had to dig up

https://www.mail-archive.com/racket-users@googlegroups.com/msg43291.html

to figure it out.

/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/CABefVgyYCFn8%3DVF8Ufr4Q_vwt2nKiTnnk-0t24%3DA%3DmxcSYkKNw%40mail.gmail.com.


Re: [racket-users] combining require, build-path, and namespaces

2020-07-21 Thread Jens Axel Søgaard
Den tir. 21. jul. 2020 kl. 17.45 skrev Shriram Krishnamurthi <
shri...@gmail.com>:

> How I can combine these three? I want to do something like this:
>
> (define n (make-base-namespace))
> (define p (build-path f))
> (eval `(require ,p) n)
>
> Racket doesn't like that: bad syntax for require sub-form because p is a
> path-typed value.
>
> Essentially, I want to inject the module at f into n so that the provided
> identifiers of f are visible inside n. (I haven't been able to get
> dynamic-require working either, nor is it an entirely satisfactory
> solution because I may not always know what names f is providing.)
>

Sounds like a job for `namespace-require` with a require spec of the form
`(file ,(path->string (build-path f)))`.

/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/CABefVgzwBhd%3D27JCRr3PDj5NKL8iukiQCsEspww%2BTBcPBUe4dQ%40mail.gmail.com.


Re: [racket-users] Font bearing - lining up texts and outlines

2020-07-21 Thread Jens Axel Søgaard
Den man. 20. jul. 2020 kl. 19.14 skrev Jens Axel Søgaard <
jensa...@soegaard.net>:

> Thanks for the response.
>
> I have attempted to go in your foot steps and have made a single file
> example, so it is easy to try out.
> Just to recap, the goal is to get the vertical bearing.
>
> The first step is to get the pict `text` numbers and the pango numbers
> (ascent, descent and height) -
> but I can't get them to match. Any hints or ideas are welcome.
>

It helps to use the correct font...

It turns out the chess rook is not in "Courier", it is in  "Arial Unicode
MS".
The raw pango functions aren't clever enough to find an alternative font,
but I think `text` from `pict` is. I am not sure of the details here though.

/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/CABefVgyw%2B8O_BnqRbpajA2JfY5O9UKpcHyQuqLsHBNVZ3AfZoA%40mail.gmail.com.


Re: [racket-users] Layout + styling in racket/gui

2020-07-07 Thread Jens Axel Søgaard
Hi Travis,

Den tir. 7. jul. 2020 kl. 00.18 skrev Travis Kiefer :

> Thank you for the example links. The spreadsheet example gets closer to
> the right direction of a non-trivial example. What's missing from these is
> the ability to add styles to the elements... Background colors, gradients,
> box shadow, border around a container element, left align, right align, et
> cetera.
>

In general (not just in Racket) the styling is more difficult in a cross
platform gui.
Since a Racket GUI program needs to run on both macOS, Linux and Windows
and still look "native" - it is usually a good idea to keep the
default appearance of
most elements. Also one must accept that guis aren't as flexible as
html/css.
The upside is that using standard elements work with custom themes used
in the OS. Screen readers for blind also work with standard elements.
Also when (strictly hypothetically of course) some OS changes buttons from
squares to circles, then nothing in your code needs changing.

However, here is where to look for different knobs to tweak:

Arranging


To place gui elements in a row: use horizontal-pane%
or horizontal-panel%
To place gui elements in a column:   use vertical-pane%
 or vertical-panel%
Use panels if you need to respond to events.
These elements support alignments and borders.

For custom placement in a row, make a subclass of horizontal-panel%.
For custom placement in a column, make a subclass of vertical-panel%.
For custom placement in a 2d-area, make a subclass of panel%.

Use vertical-pane% for left alignment.

Study:   https://docs.racket-lang.org/gui/Windowing_Classes.html?q=gui

Borders
==
For system borders use the a some kind of pane/panel to put your element in.
Then turn on the border of the pane/panel. You can also add padding by
putting an element inside a pane/panel.

Custom borders are tricky.

Canvas
==
For a canvas you have full control over colors and contents - but the
downside
is that you need to draw everything yourself.

Basic Elements

The most basic elements: mesages (labels),  buttons, check boxes, sliders
etc
are here:

https://docs.racket-lang.org/gui/control___.html?q=gui


Compound Elements / OS Elements

>From the basic elements one can build more complicated elements.
Look around in the documentation for these. If you can't find
an element ask around - chances are that you are not the first
to need a certain type of element.

Some OS level elements such as "pick a file" dialogs finder:put-file and
finder:get-file  are found in `framework` (not in `racket/gui`).


General Advice

The gui system uses classes and objects. If you need to change the
behaviour of certain elements, say, a button. One must make a
subclass, say, my-button%, that overrides/replaces the default
behaviour. Then that class must be instantiated.

Look in the 7gui repo for examples of this.

Blogs

Alex Harsányi has written many blog posts on how to use the Racket gui.
https://racket-stories.com/from/327

Other gui related blog posts:
https://racket-stories.com/from/248

Video in Racket guis:
https://www.youtube.com/watch?v=yo6wVXS6dkU

/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/CABefVgy97vqaH4uaxTs0qHBJB0k0q00XTSMYho2ijmCB3Jd4eQ%40mail.gmail.com.


Re: [racket-users] Layout + styling in racket/gui

2020-07-06 Thread Jens Axel Søgaard
If you are looking for examples of how to use the Racket GUI toolkit, I can
recommend:

https://github.com/mfelleisen/7GUI

It contains Racket implementations of the 7 gui tasks mentioned here:

https://eugenkiss.github.io/7guis/tasks

/Jens Axel

Den man. 6. jul. 2020 kl. 23.54 skrev Travis Kiefer :

> Hello all!
>
> I'm coming from the background of building web apps that are wrapped in a
> headless browser and would like to take the app development experience and
> bring it to the racket ecosystem. As an html / css / javascript engineer
> I'm finding the learning curve pretty daunting with racket's documentation
> but lack of copious examples... So I'd like to create some practice apps
> that introduce ideas / concepts that are familiar from the web app realm
> within the environment of racket...
>
> That said, what I'd like to do is build the canonical "Todo App" in
> racket/gui or an equivalent. Basically I'd like the ability to create the
> equivalent of div / layout elements, sub elements that you are familiar to
> the browser (text input, checkboxes), and the ability to mix in styles.
> Basically HTML + CSS.
>
> Ideally I'd like to create a Racket version of the following website:
> http://photonkit.com.
>
> Any resources to get started would be great.
>
> Best,
> Travis
>
> --
> 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/b88bc758-75bb-4620-b29f-c4f9b1ddf915o%40googlegroups.com
> <https://groups.google.com/d/msgid/racket-users/b88bc758-75bb-4620-b29f-c4f9b1ddf915o%40googlegroups.com?utm_medium=email_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/CABefVgyBOs9bUuFpo7oscGLEdtSjDZTxg_D6NrLLDUsjFv_Mbg%40mail.gmail.com.


Re: [racket-users] Is it possible to simulate FEXPRs in Racket?

2020-06-07 Thread Jens Axel Søgaard
Den søn. 7. jun. 2020 kl. 14.09 skrev Siyuan Chen :

Unfortunately, this code doesn't work, because it lacks two functions,
> `get-current-env` and `extends-env`.
>

These are not available since static lexical scope makes it possible for
the compiler to determine where
a variable is stored at compile time. Therefore an explicit environment is
not needed.
(See "early binding" vs "late binding").


> Is there any way to work around this issue?
>


> I have searched Racket's document. Racket has namespaces that are very
> similar to the environment here.
>
> But it seems that `current-namespace` can not get binding (e.g. Just) and
> `namespace-set-variable-value!` is a mutable function which is not suitable
> as well.
>

Namespaces are "environment-like" but contain only top-level variables.

Could someone give me some advice?
> Or we can modify the code above to make it work in Racket.
>

Since this for educational/fun use and not practical, I suggest using a
Scheme interpreter where the environments
are explicit.  Then you can easily add `get-current-env` and `extends-env`
yourself.

One option is the interpreter page LiSP (Lisp in Small Pieces) where an
interpreter for fexprs is discussed
with full working code.

/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/CABefVgwBO%2BMG6SH66mHM_-LTsxpWTBsTu-%3DKSQ-skwjmUQvBOA%40mail.gmail.com.


Re: [racket-users] Some stuff about "case".

2020-06-01 Thread Jens Axel Søgaard
Den man. 1. jun. 2020 kl. 20.53 skrev Christopher Lemmer Webber <
cweb...@dustycloud.org>:

> As I started typing this email and looking into the definition of case,
> I realized my assumptions are wrong.
>
> What I needed: something like case which dispatches on symbols, except
> not auto-quoting the arguments... I needed to evaluate them from the
> lexical environment.  So:
>
>   (let ([x 'foo])
> (caseish 'foo
>   [(x) 'got-foo]
>   [('x) 'got-quote-x]))  ; => 'got-foo
>

Sounds like `evcase`:

https://docs.racket-lang.org/mzlib/mzlib_etc.html#%28form._%28%28lib._mzlib%2Fetc..rkt%29._evcase%29%29



> I figured: case is fast, and I'm pretty sure semi-magical... my
> intuitive sense was that it did some smart things on a compiler level
> that would probably be anything I'd hand-code (which would either use an
> alist or an immutable hashtable).


I think `case` were more important before `match` arrived.
If you want to see how `case` can be implemented without hash-tables, look
at
William D Clinger's paper:

http://scheme2006.cs.uchicago.edu/07-clinger.pdf

/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/CABefVgypomV3a%3DfcgyBtrvpyAS1FeH4YR3k3zEKR9One3Niu5Q%40mail.gmail.com.


Re: [racket-users] Re: How to make DrRacket interactions window use the same reader as the definitions window?

2020-05-29 Thread Jens Axel Søgaard
There may be other solutions, but one way to control the evaluation of
expressions entered in the REPL
is to provide an   #%top-interaction, which sets the appropriate parameters.

/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/CABefVgzTpdY7rVg93iQU-MvE%2BWzx%2B%3DpQkGnWpSJ6gf0D0P_Z%3Dg%40mail.gmail.com.


Re: [racket-users] Re: Typing lag with DrRacket on Linux

2020-05-28 Thread Jens Axel Søgaard
>>>
>>> > ??? [13]
>>>100.0%
>>> > [22] 179456(100.0%) 158080(88.1%) loop
>>> .../drracket/drracket/private/rep.rkt:1456:17
>>> > ??? [3]
>>>  11.3%
>>> > wait-now [32]
>>>   0.0%
>>> >
>>> 
>>>
>>> > ??? [70]
>>>100.0%
>>> > [75]   5512(3.1%) 5512(3.1%)  channel-put
>>> ...lects/racket/private/misc.rkt:169:2
>>> >
>>> 
>>>
>>> > The culprit, to me, looks like flush-display. Do you perhaps have any
>>> thoughts on the flush-display usage within window.rkt? I will try to poke
>>> at this a bit more.
>>> >
>>> > Evan
>>> >
>>> > On Saturday, February 10, 2018 at 3:35:35 AM UTC-10, Robby Findler
>>> wrote:If you run this code, does the profiling information reveal anything
>>> >
>>> > interesting?
>>> >
>>> >
>>> >
>>> > #lang racket/gui
>>> >
>>> > (require profile)
>>> >
>>> > (define ec%
>>> >
>>> >   (class editor-canvas%
>>> >
>>> > (define/override (on-paint)
>>> >
>>> >   (profile (super on-paint)))
>>> >
>>> > (define/override (on-char e)
>>> >
>>> >   (profile (super on-char e)))
>>> >
>>> > (super-new)))
>>> >
>>> > (define frame (new frame% [label "Simple Edit"]
>>> >
>>> >[width 1800]
>>> >
>>> >[height 1800]))
>>> >
>>> > (define canvas (new ec% [parent frame]))
>>> >
>>> > (define text (new text%))
>>> >
>>> > (send canvas set-editor text)
>>> >
>>> > (send frame show #t)
>>> >
>>> >
>>> >
>>> >
>>> >
>>> > On Fri, Feb 9, 2018 at 11:05 PM, Evan Whitmer 
>>> wrote:
>>> >
>>> > > I forgot to mention that I have a 4K display, and I think that's
>>> important
>>> >
>>> > > to note here.
>>> >
>>> > >
>>> >
>>> > >
>>> >
>>> > > On Friday, February 9, 2018 at 7:00:18 PM UTC-10, Evan Whitmer
>>> wrote:
>>> >
>>> > >>
>>> >
>>> > >> I, too, am having typing latency issues in DrRacket in the
>>> definitions
>>> >
>>> > >> window. As Dave noted, the size of the window seems to be related
>>> to the
>>> >
>>> > >> issue, and, in my experience, it's not just an issue with the
>>> Definitions
>>> >
>>> > >> window. Both the Interactions window and even the following code
>>> snippet
>>> >
>>> > >> (taken from StackOverflow) will have this same lag:
>>> >
>>> > >>
>>> >
>>> > >> (define frame (new frame% [label "Simple Edit"]
>>> >
>>> > >>[width 1800]
>>> >
>>> > >>[height 1800]))
>>> >
>>> > >> (define canvas (new editor-canvas% [parent frame]))
>>> >
>>> > >> (define text (new text%))
>>> >
>>> > >> (send canvas set-editor text)
>>> >
>>> > >> (send frame show #t)
>>> >
>>> > >>
>>> >
>>> > >> (define delta (make-object style-delta% 'change-size 14))
>>> >
>>> > >> (send delta set-face "Menlo")
>>> >
>>> > >> (send text change-style delta)
>>> >
>>> > >>
>>> >
>>> > >> I am on Ubuntu 17.10 using Racket 6.11 with the proprietary nVidia
>>> drivers
>>> >
>>> > >> and X.org. My GTK version is 3. I don't have this issue with any of
>>> the
>>> >
>>> > >> other text editors that I've tried to use.
>>> >
>>> > >>
>>> >
>>> > >> I tried to profile the above text editor, but I am a novice
>>> Racketeer and
>>> >
>>> > >> could not figure out a way to profile a thread managed in
>>> racket/gui. Does
>>> >
>>> > >> anyone perhaps know of a way to hook the above into a profiler to
>>> see what
>>> >
>>> > >> might be the cause of this lag?
>>> >
>>> > >>
>>> >
>>> > >> Has anyone happened to stumble onto this issue recently and solved
>>> it?
>>> >
>>> > >>
>>> >
>>> > >> Evan
>>> >
>>> > >>
>>> >
>>> > >> On Saturday, April 1, 2017 at 6:07:28 AM UTC-10, gneuner2 wrote:
>>> >
>>> > >>>
>>> >
>>> > >>> On Fri, 31 Mar 2017 13:34:38 -0700 (PDT), Dave Musicant
>>> >
>>> > >>>  wrote:
>>> >
>>> > >>>
>>> >
>>> > >>> >I'm using DrRacket on a 64-bit Ubuntu 16.04 system with the
>>> >
>>> > >>> >default Unity windowing system, and am finding that typing
>>> >
>>> > >>> >in the definitions window is laggy.
>>> >
>>> > >>>
>>> >
>>> > >>> I've seen similar behavior on CentOS 6.5-6.8 under Gnome(2) - it
>>> has
>>> >
>>> > >>> persisted across a number of OS and Racket versions.
>>> >
>>> > >>>
>>> >
>>> > >>> I have seen the lag in Dr Racket with 6.1, 6.5, 6.7 and 6.8.  I
>>> >
>>> > >>> compiled 6.1 and 6.5 myself, so there might have been something
>>> >
>>> > >>> strange in those cases, but 6.7 and 6.8 were stock Linux x86_64
>>> >
>>> > >>> downloads.
>>> >
>>> > >>>
>>> >
>>> > >>> Turning off background expansion helps somewhat, but I have found
>>> that
>>> >
>>> > >>> limiting memory seems to help the most.  On Linux I run Dr Racket
>>> with
>>> >
>>> > >>> the limit set to 512MB.  That might be too low for some people,
>>> but it
>>> >
>>> > >>> works fine for my typical (webserver app) uses.
>>> >
>>> > >>>
>>> >
>>> > >>> George
>>> >
>>> > >>>
>>> >
>>> > > --
>>> >
>>> > > You received this message because you are subscribed to the Google
>>> Groups
>>> >
>>> > > "Racket Users" group.
>>> >
>>> > > To unsubscribe from this group and stop receiving emails from it,
>>> send an
>>> >
>>> > > email to racket-users...@googlegroups.com.
>>> >
>>> > > For more options, visit https://groups.google.com/d/optout.
>>>
>> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/racket-users/c369c5b0-9c78-4636-be07-1a36c4f35bdd%40googlegroups.com
> <https://groups.google.com/d/msgid/racket-users/c369c5b0-9c78-4636-be07-1a36c4f35bdd%40googlegroups.com?utm_medium=email_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/CABefVgwsJVtGHg-5HH2fBCbHR7JZoG%2B8QZRcbbLRYBbBA6ckyw%40mail.gmail.com.


Re: [racket-users] coding style query

2020-05-27 Thread Jens Axel Søgaard
Den ons. 27. maj 2020 kl. 19.56 skrev Hendrik Boom :

> Is there an accepted convention about how to use a symbol used in a
> program within a comment so it's clear the comment is using it as a
> program symbol and not as an ordinary English word?
>

Not sure. Sometimes I surround the symbol with two spaces to each side
instead of just one.
Can't remember where I picked that habit up.

/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/CABefVgyY%3DGY%2BOTNxfEZLkaZaqpZi%3DGF6%3DVgrPThRJoY7_g%40mail.gmail.com.


Re: [racket-users] Function that potentially can return more than one value

2020-05-27 Thread Jens Axel Søgaard
Den ons. 27. maj 2020 kl. 19.27 skrev George Neuner :

>
> On 5/27/2020 6:34 AM, Jens Axel Søgaard wrote:
> >
> > In standard Racket an application doesn't communicate how many values
> > a function is expected to produce.
>
> You can ask:  see procedure-result-arity
>  https://docs.racket-lang.org/reference/procedures.html


I think  procedure-result-arity  answers the question "how many
values could this procedure return?" and not "how many values
is the procedure expected to return in this context?".


> > I have written a small proof-of-concept of an assignment operator :=
> > that communicates to a function how many extra values it is expected
> > to produce (and still works with standard functions).
> >
> > Are there alternative solutions that are better than the "use a
> > keyword" approach?
>
> You can use  call-with-values  which connects the function that produces
> with the one that consumes, but they have to agree on the number of
> values being passed or it won't work.
>

My problem is that the producer still needs to be told how many values to
produce.

/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/CABefVgwy4YEPcswLjLEf-FN2sZMa2xbPqOWxOJ%3DdOEnEUF6_Hg%40mail.gmail.com.


Re: [racket-users] Migrating from a "model-driven" language framework to Racket

2020-05-25 Thread Jens Axel Søgaard
age 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/3ee19998-88bf-48f7-8129-c1be9419d4c9%40googlegroups.com
> <https://groups.google.com/d/msgid/racket-users/3ee19998-88bf-48f7-8129-c1be9419d4c9%40googlegroups.com?utm_medium=email_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/CABefVgxGkkbYFNHRNHEt5WnmDiH%2Buw%3DQhh-fotm59gHAc7tJTg%40mail.gmail.com.


Re: [racket-users] Re: Practical HTTP requests?

2020-05-17 Thread Jens Axel Søgaard
would make Racket practical for my use at work:
>>>
>>>- Make a series of HTTP requests to an API that returns JSON
>>>responses
>>>- Reuse the HTTP connection to avoid creating new TCP connections
>>>for each request
>>>- Honors the `http_proxy`, `https_proxy`, and `no_proxy` environment
>>>variables
>>>- Maintains a "session" where cookies set by the server are sent
>>>back in subsequent requests
>>>
>>> My daily driver is Python, so I'm used to its `requests` library. Go and
>>> Rust have similar libraries. While I don't mind piecing some of this
>>> together, I'm struggling as a new user to figure out what libraries are
>>> recommended and, more importantly, how to put them together to accomplish
>>> the above points.
>>>
>>> Thank you.
>>>
>>> p.s. The Racket documentation is by far the best looking documentation
>>> I've read in any language. It's quite amazing!
>>>
>>> --
> 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/f71ad314-677f-4f42-ae7c-9e738d88eded%40googlegroups.com
> <https://groups.google.com/d/msgid/racket-users/f71ad314-677f-4f42-ae7c-9e738d88eded%40googlegroups.com?utm_medium=email_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/CABefVgwOsawWBBoF9drpj6SW2w8vwP8XW3uepgSOx1ZHqWY%2B9Q%40mail.gmail.com.


Re: [racket-users] Re: Strange behaviour of ptr-ref + ptr-add(?)

2020-05-10 Thread Jens Axel Søgaard
I can confirm that the bug is present in the latest snapshot of Racket CS
on macOS.

FWIW  _double* is missing in this list, but I am not sure it whether it is
supposed to be handled here.
https://github.com/racket/racket/blob/920c899ba866ce59a0387862286521e3cc1dabfb/racket/src/schemify/ptr-ref-set.rkt#L46

/Jens Axel

Den søn. 10. maj 2020 kl. 10.51 skrev Laurent :

> Correction:
> It's not Mac vs Linux, it's Racket BC (works) vs CS (doesn't work)
>
> On Sun, May 10, 2020 at 9:49 AM Laurent  wrote:
>
>> Hi all,
>>
>> We're trying to figure out why the last case below doesn't work on
>> Linux, but works on MacOS. Does anyone have an explanation?
>> The docs suggest that _double* shouldn't be different from _double for
>> _reading_ values.
>>
>> More precisely,
>>
>> #lang racket
>> (require ffi/unsafe)
>>
>> (define N 10)
>> (define pt (malloc N _double 'atomic-interior))
>> (for ([i (in-range N)])
>>   (ptr-set! pt _double* i (+ 2. i)))
>>
>> ;; works
>> (for/list ([i (in-range N)])
>>   (ptr-ref pt _double i))
>>
>> ;; works
>> (for/list ([i (in-range N)])
>>   (ptr-ref (ptr-add pt i _double) _double*))
>>
>> ;; doesn't work!
>> (for/list ([i (in-range N)])
>>   (ptr-ref (ptr-add pt i _double) _double))
>>
>> --
>> Output:
>> (2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0 11.0)
>> (2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0 11.0)
>> (2.0 2.0 2.0 2.0 2.0 2.0 2.0 2.0 2.0 2.0)
>>
>> --
> 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/CABNTSaFmfgTpTrWzfcxL%2BxQCqtge5Ls1eKW%2Bp0ftd%3D0q554ALg%40mail.gmail.com
> <https://groups.google.com/d/msgid/racket-users/CABNTSaFmfgTpTrWzfcxL%2BxQCqtge5Ls1eKW%2Bp0ftd%3D0q554ALg%40mail.gmail.com?utm_medium=email_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/CABefVgzNsmOEx3LV%3DvmV--gu3UD6kHZsRCfPQm0kn32Vo_ziKw%40mail.gmail.com.


Re: [racket-users] A convenient assertion macro - with one caveat

2020-05-07 Thread Jens Axel Søgaard
You can use syntax/loc to give a piece of syntax location information.

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

(define-syntax (assert stx)
  (syntax-parse stx
[(_assert ?a ?b)
 (quasisyntax/loc stx
   (module+ test
 (require rackunit)
 #,(syntax/loc stx (check-equal? ?a ?b #'?a]
[(_assert ?a)
 (quasisyntax/loc stx
   (module+ test
 (require rackunit)
 #,(syntax/loc stx (check-true ?a #'?a]))


/Jens Axel
Racket Stories
https://racket-stories.com

Den tor. 7. maj 2020 kl. 11.22 skrev Dexter Lagan :

> Hi,
>
>   I made a simple macro which saves me the trouble of defining a test
> module, requiring RackUnit and then declaring '(module+ test' after each
> procedure definition, as I like to keep unit tests close by. The repo :
>
> https://github.com/DexterLagan/assert
>
>   Here's the macro, apologies for the broken formatting :
>
> (define-syntax (assert stx)
> (syntax-parse stx
> [(_ ?a ?b)
> #'(module+ test
> (require rackunit)
> (check-equal? ?a ?b #'?a))]
> [(_ ?a)
> #'(module+ test
> (require rackunit)
> (check-true ?a #'?a))]))
>
> The macro works great, and I was able to pipe through an assertion message
> through rackunit's check-equal? and other procedures.
> I have one question however: would there be a way to make DrRacket point
> to the failed assertion line instead of the macro itself when a failure
> occurs? Here's a screenshot of how it looks like at the moment:
>
> [image: assert.PNG]
>
>   It would be even better if DrRacket highlighted the (assert ...) line
> itself, but I'm asking a bit much :) If assert is an actual module, I'm not
> sure where DrRacket would then point at.
> I also have doubts about whenever Racket will remove the test module once
> compiled. Since macros are processed at compile-time, I'm guessing it would
> remove the test module right after, but let me know if you have a more
> definite answer.
>
> Dex
>
> --
> 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/CACUENrLX%3D9ix2kv9MNpp3nNoSN%3DsWBx%2BFTRdwNyNA7EiVWQ0mA%40mail.gmail.com
> <https://groups.google.com/d/msgid/racket-users/CACUENrLX%3D9ix2kv9MNpp3nNoSN%3DsWBx%2BFTRdwNyNA7EiVWQ0mA%40mail.gmail.com?utm_medium=email_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/CABefVgyO8hOc7veBwQF7isSPD7YA77wV%3Dxa4y9EhBxB5Z9hQFQ%40mail.gmail.com.


Re: [racket-users] a minor regexp question (and a how-could-I-answer-it-myself? question)

2020-05-01 Thread Jens Axel Søgaard
Den fre. 1. maj 2020 kl. 14.20 skrev Tim Hanson :

> hi, just now I'm debugging a regular expression and trying to understand
> why this:
>
>   > (regexp-match-positions #rx"[-+][0-9]+" "-0500")
>   '((0 . 5))
>
> works as I expect, whereas this:
>
>   > (regexp-match-positions #rx"[-+][0-9]{4}" "-0500")
>   #f
>
> doesn't. (My naive opinion is the second expression should return the same
> answer as the first.)
>

The cause of the confusion is that there are several notations for regular
expressions.
Racket supports two types "egrep" and "Perl" ones.
Turns out the repetition syntax with braces {} are only supported in Perl
regular expressions.
Therefore you need to use #px rather than #rx.

The relevant section of the documentation:

[image: image.png]



> Wondering whether I could discover for myself whether this is a known
> issue, I found directly:
>
>   https://github.com/racket/racket/search?q=regexp=Issues
>
> or perhaps something like this:
>
>
> https://github.com/racket/racket/search?q=regexp+type%3Aissue_q=regexp+type%3Aissue
>
> is better, but either way I'm quickly pretty lost in terms of deciding
> whether this relates to a known issue.
>

You need to look at docs.racket-lang.org instead. Then search for "regexp"
or "regular expression".
You will then end up here:

https://docs.racket-lang.org/reference/regexp.html?q=regular%20expression

Also ... if it is any consolation ... you are not the first to be confused
by this.

/Jens Axel

Racket Stories
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/CABefVgx%3D9iTX5op3G4KaJ5Wt2dNDcOVE%2BWV%3DJ3jct_JEWDnEKQ%40mail.gmail.com.


Re: [racket-users] Question on test failures sorting a BTS

2020-04-27 Thread Jens Axel Søgaard
Den man. 27. apr. 2020 kl. 04.36 skrev Kristina Marie :

> Hello,
> I am trying to use HtDF to create a function to sort a Binary Search Tree.
> I am in an intro class so this may be a simple question. I did the
> following:
>
> ;define-struct a node
> (define-struct node (left value right))
>
...

> ; Purpose: sort a binary tree
> ; Signature: node -> list
> ; Examples:
> (check-expect (bst-sort null)(list))
> (check-expect (bst-sort a-node)(list "A"))
> (check-expect (bst-sort j-node)(list "H" "I" "J"))
> (check-expect (bst-sort root)(list "A" "B" "C" "D" "E" "F" "G" "H" "I" "J"
> "K"))
>
> ;Code
> (define (bst-sort nod)
>   (cond
> [(null? nod)(list)]
> [(and (null? (node-left nod)) (null?(node-right nod)))
> (list(node-value nod))]
>[else
>(string-append (bst-sort (node-left nod) (list (node-value
> nod)) (bst-sort (node-right nod
>]
>)
>  )
>
>
This expression
 (bst-sort (node-left nod) (list (node-value nod)) (bst-sort
(node-right nod
is the problem. It can be reformatted to make it clearer:

 (bst-sort (node-left nod)
   (list (node-value nod))
(bst-sort (node-right nod

You are providing 3 arguments to bst-sort, but according to your signature:
; Signature: node -> list
it only takes one input.

Furthermore the `string-append` needs to be removed, since bst-sort returns
a list, not a string.

/Jens Axel



> I keep getting this test failure:
> bst-sort: expects only 1 argument, but found 3
>
> It has to due with the two last check-expects failing because of the
> highlighted line.
>
> I ran this same code with integers and removed the string from append and
> it passed. Any advice?
>
> --
> 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/e5e05ebe-87ed-4d49-8a18-d3b58bae4e38%40googlegroups.com
> <https://groups.google.com/d/msgid/racket-users/e5e05ebe-87ed-4d49-8a18-d3b58bae4e38%40googlegroups.com?utm_medium=email_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/CABefVgyyOCTLVomOhEWtOT%3DOOOdyNM%2BxcSEee4kdDctbspBDOg%40mail.gmail.com.


Re: [racket-users] rename-in issue

2020-04-09 Thread Jens Axel Søgaard
Den tor. 9. apr. 2020 kl. 11.04 skrev Lucas Liendo :

> Hi everyone! I've a very dumb question (as still not very experienced
> Racket programmer), I'm doing the following:
>
> (require net/url
>  web-server/dispatchers/filesystem-map
>  (rename-in web-server/dispatchers/dispatch-files
> (make dispatch-files))
>  (rename-in web-server/dispatchers/dispatch-sequencer
> (make dispatch-sequencer)))
>
> As you can see `make` is defined both in
> `web-server/dispatchers/dispatch-files` and
> `web-server/dispatchers/dispatch-sequencer` and I think that's the
> reason for this error:
>
> /tmp/rename-example.rkt:7:20: module: identifier already required
>   at: interface-version
>

This shows that interface-version is the (new) cultprit.
You can rename it to avoid a collision - or if you don't need it, you can
simply omit it:

#lang racket
(require net/url
 web-server/dispatchers/filesystem-map
 (rename-in web-server/dispatchers/dispatch-files
(make dispatch-files))
 (except-in (rename-in web-server/dispatchers/dispatch-sequencer
   (make dispatch-sequencer))
interface-version))


/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/CABefVgx3Qv72EGM%3DfzKK1rNrcCmnoCVy5%2BQxpPGH5HPusB%3D5bw%40mail.gmail.com.


Re: [racket-users] BLAS and LAPACK bindings for operations over math/matrix

2020-03-28 Thread Jens Axel Søgaard
Den lør. 28. mar. 2020 kl. 12.37 skrev Pratyush Das :

> So, this is what I found when I was looking for a Racket library with BLAS
> and LAPACK bindings -
> https://github.com/soegaard/flmatrix
> https://github.com/farr/PLT-Racket-Linear-Algebra-Bindings
>
> But they implement their own matrices and use the bindings for operations
> over them.
>
Are there any implementations that use BLAS and LAPACK bindings for
> operations over matrices created using the math/matrix racket extension?
>

Not that I know of.

The way matrices are stored in `math/matrix` is not suitable for passing to
BLAS directly.
The library `math/matrix` uses functional arrays to store the elements.
The library BLAS on the other hand expects piece of memory in which the
elements are laid out in a particular way.
So if you have a math/matrix matrix and want to use a BLAS operation, you
will need write conversion functions.

/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/CABefVgzqPxo_9tWPMAcVK70W7%3DRKJfUAWhh5m9kJBbmAeLbzOw%40mail.gmail.com.


Re: [racket-users] Help with vector-sort

2020-02-15 Thread Jens Axel Søgaard
Den lør. 15. feb. 2020 kl. 13.44 skrev greadey :

> I have written a programme to compute a bootstrapped mean etc.  I
> successfully wrote it using lists both untyped and in typed/racket.
> I am interested in optimising the code and having seen that typed racket
> performs faster (for lists) I am interested in seeing if I get a
> performance increase using vectors in both typed and untyped code.
> In order to compute the median value as well as certain percentiles it is
> necessary to sort the samples.  My specific problem is using vector-sort.
> I have got round it by using vector->list and list->vector functions and
> using the list sort function.
> If I use vector-sort typed racket keeps telling me to use
> "require/typed".  I got a function definition to compile  (:sort-myvector :
> (Vectorof Flonum) (Flonum Flonum -> Boolean) -> (Vectorof Flonum))
> I'm not sure if that is exactly right but it was something similar,
> however it did not work.  I did add a "require/typed racket/vector" to the
> expression.
> So, how can I use vector-sort in typed racket code, and can anyone tell me
> if translating vectors to lists and back again actually introduces a
> performance hit?
>

Here is an example of how to use `vector-sort` from a typed/racket program:

#lang typed/racket
(require/typed racket/vector
  [vector-sort (-> (Vectorof Any) (-> Any Any Boolean) (Vectorof Any))])

(define (compare x y)
  (if (and (real? x) (real? y))
  (< x y)
  (error 'compare "expected two real numbers, got: ~a ~a" x y)))

(vector-sort (vector 3 1 5 2) compare)

/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/CABefVgzOSTZJs%2BaZADFxe8oPJ%2BNx4ihvjHjJ19BcqhF2oKkayQ%40mail.gmail.com.


Re: [racket-users] resources for learning JS / React?

2020-01-26 Thread Jens Axel Søgaard
If he is using React for a new project, I suggest using React Hooks.
React Hooks were introduced in 2018 and "feels more functional" than their
previous approach.

https://reactjs.org/docs/hooks-intro.html

/Jens Axel


Den søn. 26. jan. 2020 kl. 18.12 skrev 'John Clements' via Racket Users <
racket-users@googlegroups.com>:

> Many thanks! These look good.
>
> John Clements
>
> > On Jan 26, 2020, at 05:15, Darren Newton  wrote:
> >
> > For learning JavaScript these two resources are very good:
> >
> > Eloquent JavaScript https://eloquentjavascript.net/
> > You Don't Know JS https://github.com/getify/You-Dont-Know-JS
> >
> > The tutorial on the React site itself is pretty good and provides a
> solid foundation in the framework -
> https://reactjs.org/tutorial/tutorial.html
> >
> >
> >
> > On Saturday, January 25, 2020 at 1:56:57 PM UTC-5, 'John Clements' via
> users-redirect wrote:
> > I have a graduate student that wants a self-guided introduction to JS
> and React. The problem here, to some degree, is that there are so *many*
> introductions. Does anyone here have specific references that might be
> helpful? (Say, e.g., if Gregor Kiczales did a JS course on coursera… that
> would be pretty much perfect.)
> >
> > John
> >
> >
> > --
> > 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/4dc7e361-7ea1-490a-993a-210a364c70f7%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/f244ae71-9d34-4c23-aaf7-3fe931efd392%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/CABefVgyiO69XCjpZmVrRu4yys8DmqbPbM5kd-Wh2akr%3DU%3Drvyg%40mail.gmail.com.


Re: [racket-users] Web server + authentication

2020-01-23 Thread Jens Axel Søgaard
Den tor. 23. jan. 2020 kl. 01.47 skrev Matthew Butterick :

> I concur on Postmark. For 2+ yrs I've used it with the Racket web server
> for mbtype.com. I pass the server settings to `smtp-send-message` from `
> net/smtp`.
>
> On 22 Jan 20, at 3:00 AM, Bogdan Popa  wrote:
>
> I like using Postmark[0] for this.  Their free plan lets you send up to
> 100 e-mails a month, their paid plans come at a reasonable price and
> they have helpful docs and validators to help you set up SPF, DMARC and
> DKIM.
>
> Two recommendations!

I took a second look at Postmark and was impressed by their service,
so I went ahead and added password recovery emails via Postmark.

Some nice features:
- don't need to setup and maintain a mail server
- weekly report on the "spam status" of your domain
- email templates (html mails are hard)
- an ios app to track mails
- 100 mails free pr month (which for Racket Stories is plenty)

Thanks for the push.


Stephen, I think, password resets were what you originally asked for (see
latest commit).

 https://github.com/soegaard/racket-stories

The code hasn't been deployed yet - it'll happen sometime tomorrow.

Philip: I'll keep your solution in mind, if I for some reason need to
change it.

/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/CABefVgzNd2ZF1fpChjPKu9uYP1JambVJNzONUqKeTquPR-v2Lg%40mail.gmail.com.


Re: [racket-users] Web server + authentication

2020-01-21 Thread Jens Axel Søgaard
Look at `koyo`.

https://docs.racket-lang.org/koyo/index.html?q=koyo

For simple user login with secure sessions look at

https://github.com/soegaard/racket-stories/blob/master/app-racket-stories/control.rkt#L58

But I haven't implemented "reset password" functionality yet. I need to
figure out how best to handle sending mails
from a server. My concern is being flagged for spamming - so I don't dare
use my normal mail.

/Jens Axel


Den tir. 21. jan. 2020 kl. 22.43 skrev Stephen Foster <
step...@thoughtstem.com>:

> Ruby on Rails has a nice package called Devise, which handles things like:
> letting users log into your webapp, letting them reset their passwords,
> etc.  In the Racket ecosystem, I'm struggling even to find examples of
> managing users.
>
> I'm about to start digging here:
> https://github.com/tonyg/racket-pkg-website
>
> Are there other places I could look?
>
>
> --
> 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/93a77b99-f238-4315-9f10-0b1aa6929262%40googlegroups.com
> <https://groups.google.com/d/msgid/racket-users/93a77b99-f238-4315-9f10-0b1aa6929262%40googlegroups.com?utm_medium=email_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/CABefVgy7WPh4bB%2BZeBM_mdMjJ8%2B_BHvA%2B50Y%2B4LU%3Dmk%3DuVgooQ%40mail.gmail.com.


Re: [racket-users] GUI (get-directory)

2019-12-05 Thread Jens Axel Søgaard
FWIW I just found an introduction to Racket GUIs by Andres Ramos:

https://www.youtube.com/watch?v=yo6wVXS6dkU

/soegaard

Den tir. 19. nov. 2019 kl. 18.49 skrev pow bam :

> Hello, I am very new to programming and up until this point I had only
> seriously messed with the AutoIt language - it was easy to search and find
> out how to do things as their forums were quite active and already
> possessed a wealth of data that any determined person could get by on with
> just search alone and never needing to actively post. I built myself an
> entire program in this fashion, learning as I went. I decided I wanted to
> learn how to do this in a "real" full-blown language (tho you could easily
> argue that AutoIt is a full language now). I've decided that I love the
> idea of Lisp and Racket in particular but I am hitting roadblocks to that
> goal as the search functionality and community just isn't near the level of
> AutoIt. So here I am, actually posting in the only place it appears I can..
>
> I am trying to make use of (get-directory) which pops up a GUI prompt
> asking a user to select a directory..
>
> https://docs.racket-lang.org/gui/Windowing_Functions.html#%28def._%28%28lib._mred%2Fmain..rkt%29._get-directory%29%29
>
> Here is my code which works..
>
> #lang racket/gui
> (require racket/class)
> (define gds-main
>   (new frame%
>[label "GD Switcher"]
>[width 250]
>[height 300]
>[style '(no-resize-border)]))
> (define panel-1
>   (new vertical-panel%
>[parent gds-main]
>[style '(border)]
>[alignment '(center center)]))
> (new choice%
>  [parent panel-1]
>  [label #f]
>  [choices '("Forgotten Gods"
> "Ashes of Malmouth"
> "Vanilla Ice Cream")])
> (get-directory)
> (send gds-main center 'both)
> (send gds-main show #t)
>
>
> ..if I just use get directory as-is but if I try
>
> (get-directory [message "Select a folder.."])
>
> in any combination, and I've tried so many, it only ever gives me back the
> error..
>
> message: unbound identifier in: message
>
> What am I missing, how do I make this work?
>
> Thank you in advance for any insight.
>
> --
> 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/67dff8ff-cbd2-4d26-8901-34fc2be43928%40googlegroups.com
> <https://groups.google.com/d/msgid/racket-users/67dff8ff-cbd2-4d26-8901-34fc2be43928%40googlegroups.com?utm_medium=email_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/CABefVgzEfWzbbrosdotifEhVHn3eQ%3DAbCeTY%2BZUGdRLEodT8DA%40mail.gmail.com.


Re: [racket-users] Question regarding use of Scribble PDF button (and scribble-math) under Windows

2019-11-25 Thread Jens Axel Søgaard
Den tir. 26. nov. 2019 kl. 01.18 skrev E Comer :

> Hi Racket friends:
>
> The running of the following code produce an error under Windows, when I
> try to generate a PDF with the Scribble PDF button under DrRacket 7.5.
>
>
Which error?

/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/CABefVgwMjjow873pR_EOxtvN8MMPVnqLo9%3DZE%3Da0JzKJJwA7qA%40mail.gmail.com.


[racket-users] Parameters and dynamic-require

2019-11-10 Thread Jens Axel Søgaard
Hi All,

How can I set a parameter used in a dynamically required module?

Example:
A parameter `out` is defined in a module p.
Before requiring (dynamically) module a, we want to set the parameter.

The attempt below fails.

(module p racket/base (define out (make-parameter 'original-value))
(provide out))
(module a racket/base (require 'p) (displayln (list 'a (out))) (define
a 43) (provide a))
(require 'p)
(displayln (out))
(out "foo")
(dynamic-require ''a 'a)

The output is:
(a original-value)
original-value
43

I am hoping to see (a "foo").

/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/CABefVgxbZ5Jo1Gee8PCEArHSTrT9TBqcvUCZJoKB0QV3duHEgw%40mail.gmail.com.


Re: [racket-users] eq? of quoted expressions

2019-10-25 Thread Jens Axel Søgaard
Den fre. 25. okt. 2019 kl. 16.35 skrev wanderley.guimar...@gmail.com <
wanderley.guimar...@gmail.com>:

> Why (eq? (quote a) (quote a)) is #t but (eq? (quote (a)) (quote (a)))
> is #f?  I would expect that if (quote (a)) was a mutable pair but it
> is not since (quote (a)) returns #f.  It seems that guile returns #t
> as I was expecting.
>

Racket (and Scheme) interns symbol literals. That is, if you put the
literal '(foo foo) in your code
you will get a list value of length two, its elements are both the same
symbol spelled foo.
On the other hand in Scheme '("foo" "foo") will get you a list value of
length two. The
elements of the lists are two strings, which may or may not be the same
string (since strings
are neither guaranteed to be interned (nor not to be interned) in Scheme).

If the same literal appears twice in the source code some Scheme
implementations
will use the same value twice. So in '(foo) '(foo) the two list literals
may or may not
return the same value. List values aren't guaranteed to be interned, so
(eq? '(foo) '(foo)) may or may not return true in a Scheme implementation.

Note that this explains why Schemers write

(define magic (list 'magic))

and not

  (define magic '(magic))

in order to obtain a unique value, not eq? to any other value.

In order to allowing implementations to share values in literals in R5RS it
is unspecified
what happens when you mutate a literal.

/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/CABefVgyZ5TUABV%2Baw6G0vtohjeuJ0NXZPG0Ju3U4wXAK_o%3Dsnw%40mail.gmail.com.


Re: [racket-users] Some guidance in setting up Racket as a game scripting language.

2019-10-07 Thread Jens Axel Søgaard
Den man. 7. okt. 2019 kl. 20.15 skrev Hans Sjunnesson <
hans.sjunnes...@gmail.com>:

> I'm sorry Jens - I'm using Visual Studio on Windows to compile this
> project.
> I've initially built libracket, and SDL, which I'm linking against.
> I can zip the entire solution and upload it somewhere for you to have a
> look, but you'll need Visual Studio on Windows for that to work.
>

I don't have a windows machine - but your test example only have two files.
Is there a way to see
what options are applied (in a log perhaps)?

/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/CABefVgyMGUdFh28S_3r39K%3Dpx%3DmtEvxF%3DOiqpxYKDpA7TPvgCA%40mail.gmail.com.


Re: [racket-users] Some guidance in setting up Racket as a game scripting language.

2019-10-05 Thread Jens Axel Søgaard
Den ons. 2. okt. 2019 kl. 15.31 skrev Hans Sjunnesson <
hans.sjunnes...@gmail.com>:

> This is a hobby project of mine - a game in C, using SDL. I'd like to only
> use C for the rendering part - rather use a scripting language for all of
> the gameplay code. I want to try to use Racket for this - I've been doing
> enough Clojure that I'm familiar with a lisp. My first approach was to
> following along "Embedding into a Program" section of the Racket guide. But
> I'm running into road blocks - and I can't find any good examples of
> projects which embed Racket in a C program that calls functions in a Racket
> environment. My initial plan was to define a Racket module that provided an
> "init", an "update", and a "draw" function, then call those from the C
> program. The embedding guide points me to using "raco" to generate a C
> version of "racket/base", and that works - I can eval basic stuff, but I'm
> getting an error when I (require "test.rkt"). So I'm guessing there's more
> to be done with setting up the environment.
>

How do I compile the two test files?
In the reddit thread you said, I should start with:
raco ctool --c-mods base.c ++lib racket/base

But what are the options for gcc and the linker?

/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/CABefVgzAAjXDc2871uc-VFrmLNGw%3DeJ3-w9QAj3frHXhvFrqCA%40mail.gmail.com.


[racket-users] Racket Stories

2019-10-02 Thread Jens Axel Søgaard
Hi All,

As the Slack users already know, I have created a little web-site to share
interesting stories/links/blogs/packages/papers on everything
Racket-related.

https://racket-stories.com

Click "submit" to submit your own stories.

/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/CABefVgyxcwgPA%3Dwdb2HA8mUaFdAiK1FjfEur%3DoDet4e6s5g4xw%40mail.gmail.com.


Re: [racket-users] General ways and concrete examples of approaching web dev

2019-09-30 Thread Jens Axel Søgaard
Hi Marc,

Den tir. 24. sep. 2019 kl. 21.28 skrev Marc Kaufmann <
marc.kaufman...@gmail.com>:

> TL;DR: What are some patterns/approaches for web sites for which Racket is
> particularly suited *and* for which you can point at decently written up
> examples in Racket or other languages that share such features?
>

A big question on which I will punt.


> Much longer me:
>
> I spent much of summer implementing online web sites with quite a bit of
> state (do step 1; if answer a do step 2, if answer b do step 3; keep
> forking, randomize some things in between). The first website I did in
> Django, because 2 years ago when I rolled my own in Racket, I ended up with
> an unmaintainable mess of code that had sql and sexpr sprinkled across all
> types of files, and I didn't dare touch anything anymore. Now I learned
> that I am perfectly capable of writing an unmaintainable mess of code in
> Python too. Hence the second such web site (all are used for economic
> experiments, think surveys with a lot of randomization and if/then logic)
> is again back to Racket.
>
> The thing is that, while I know about MVC and grok it better after having
> spent time with Django, I am often at a loss to figure out where to draw
> boundaries in Racket. This is true for Django too, but there are so many
> examples out there, that it is easier to figure out what belongs where, and
> Django forces you to put some things in the models (more or less) and
> others in the views. And all the standard stuff - forms, simple SQL - has
> obvious ways of doing it. There are some things I dislike about it, but
> these are some positives.
>
> Now that I am back in Racket land, and at least partially get what
> continuations do (thanks to primarily Philip, George, Jesse, Bogdan and
> Matthew B's writings and answers on this list over the years), my code is
> vastly better than 2 years ago. Yet, I still feel that it is pretty bad,
> and I see loads of duplications that I do, sometimes due to lack of time to
> refactor, but just as often because I have no clue how to refactor it in a
> way that will not make it ridiculously fine-tuned to my current purpose.
>
> So, my question is this: what approches (if you like big ponderous words,
> what paradigms) and patterns are there to write web sites, and are you
> aware of examples that highlight them *concretely* in code in a way that
> the send/suspend/dispatch is described in the "Continue: ..." tutorial?
> Here are approaches that I know of:
>
> - MVC: Django and Rails for instance, easy to find examples. Usually
> object oriented it seems, but it's sort of what I do in Racket as well.
> - Single-Page Apps: I never implemented one, but my sense was that you can
> do MVC with it too, and it's more about whether you use JS to do things
> asynchronously. I may be wrong and there might be more to it.
> - Continuation style: What "Continue" does, and again it's not really an
> alternative to MVC, but more how you implement it (or other things). I
> still struggle a lot with doing this well, as there are few descriptions of
> it that go beyond "Continue". When I google, it brings up essentially the
> Racket crowd and something called Seaside (I had never heard of it)
> - Microservices (I do not get what it is, if it even is one thing)
>
> So what are examples in Racket or Racket-like languages (semantics, not
> syntax, so it doesn't have to look Lispy if it is functional or uses
> continuations or whatever features of Racket) that I could use to guide how
> I *could* structure my web site in a given way? Django isn't that great a
> fit since it has a pretty heavy ORM, and does lots of magic behind the
> scenes on objects, which is not trivial to map to the functional style of
> Racket.
>
> I don't know whether these are related to it, but half (all?) of my
> struggles come from trying to manage the state people are in and ending up
> passing around biggish objects, or adding 2 or more boolean fields per page
> to the database and calling the database on every new page.
>
> I understand that this is not the most well-formed question on this email
> list and it's likely I am asking the wrong question, so I am very open to
> being told "What you should be asking is ... " (such as, this is not about
> web stuff, but ...).
>

I am still a beginner in the art of crafting web sites, but here is my
perspective.
There are many ways to organise web apps. Most patterns that work in other
languages will also work in Racket.

A popular approach is to make the web app "stateless" meaning that all
state is stored on a database.
This makes scaling easy, just add more web-servers and let the load
balancer direct the traffic
to the web server with minimal load.

The MVC approach fits well here.

The model takes care of representing and storing data in the database.
All "business logic" is handled in the model as well.

The view produces html pages based on data to be presented.
The view never calls functions provided by 

Re: [racket-users] syntax-parse ellipsis question

2019-09-21 Thread Jens Axel Søgaard
Den lør. 21. sep. 2019 kl. 22.15 skrev Jonathan Simpson :

> Given this macro that I'm experimenting with:
>
> (syntax-parse #'(1 2 2 a 2 2 b 2 c) [(1 (~seq n:nat ...+ x) ...) #'((n ...
> x) ...)])
>
> How would I change it so that it returns #'(2 2 a 2 2 b 2 c) instead of
> #'((2 2 a) (2 2 b) (2 c)) ?
>
> I don't want the parens around the individual sequences that I'm matching,
> but I haven't figured out a way to do this without using a pattern that
> forces me to add them in the body of the syntax-parse clause. How can I
> group the n and x pattern variables in the body without adding parens
> around them?
>
> If could get a syntax class that replaces the (~seq n:nat ...+ x) that
> might work but I haven't been able to get a syntax class that will do that
> either.
>

Two options:

(syntax-parse #'(1 2 2 a 2 2 b 2 c)
  [(1 (~seq n:nat ...+) x ...) #'(n ... x ...)])

(syntax-parse #'(1 2 2 a 2 2 b 2 c)
  [(1 n:nat ...+ x ...) #'(n ... x ...)])

/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/CABefVgxf-ORmDHZsSRv2G46FGbpUiFq7txnHK%2B2gdzEnb0RjYQ%40mail.gmail.com.


Re: [racket-users] How to disable back button in web application

2019-09-21 Thread Jens Axel Søgaard
Den lør. 21. sep. 2019 kl. 10.05 skrev Marc Kaufmann <
marc.kaufman...@gmail.com>:

> Could I use the send/forward to essentially disable forms if I use as the
> `action` attribute on the form an (embed-url ...), which will no longer
> work later on? This will probably through an error if people do the 'Go
> back, resubmit' cycle, but I don't mind throwing an error on that, rather
> than gracefully failing. I'm not going to win any design contests that way,
> but solve a problem without dealing with any database interactions.
>

To avoid using a database, you could use a hash table to store the keys.

/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/CABefVgyCy2u84Axa09DpR8UDNMPvAH-30OjN1JhjF7%2BRAdSSpQ%40mail.gmail.com.


Re: [racket-users] How to disable back button in web application

2019-09-20 Thread Jens Axel Søgaard
Den fre. 20. sep. 2019 kl. 13.51 skrev Marc Kaufmann <
marc.kaufman...@gmail.com>:

> Thanks Jens, yes the send/forward seems to at least address a few of the
> cases that I have - not sure if it disallows the forms unless I use
> continuations in the forms (right now I am not, mostly just sending the
> request to the current URL. I'll have to see.
>
> Yes, I worked through and read the Continue tutorial a few times and use
> redirect/get to work around the double submit error. But -- I think -- the
> redirect/get only avoids something like refreshing the page from leading to
> a new submit, although I may be wrong. I thought I used it in some places
> where I was able to go back and resubmit. I should double check, since I am
> not using redirect/get everywhere, so that may be the issue.
>

Yes, the redirect trick only prevents the same data (as the result of a
"submit" action) being sent twice.
If the user goes back to the form, fills in the form again and the click
submit again, a new set
of data is sent.

If you need to prevent the same form being filled in twice, you could
associate a key as
a hidden form value (say the md5 of a counter) and keep track in a database
of which keys
have already been used.

To prevent the key table from getting too large, you can flip it around:
keep the non-used keys in the
database, then on submission remove the key. If you also store the age of
the key, you can
from time to time delete old keys.

/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/CABefVgzZw%2BpkRuP9t6axMJcmpvCKPhda1Jxnaat02XRvG6A1TQ%40mail.gmail.com.


Re: [racket-users] How to disable back button in web application

2019-09-20 Thread Jens Axel Søgaard
Is `send/forward` what you need?

Den fre. 20. sep. 2019 kl. 11.43 skrev Marc Kaufmann <
marc.kaufman...@gmail.com>:

> Hi all,
>
> disclaimer: I am guessing that my current design simply doesn't allow me
> (easily) what I want, but there may be a solution I am unaware of.
>
> In my Racket-powered website I want to disable the back button or keep
> people from using the back button to resubmit (with different data) a
> previous form or hit a link that is an embedded continuation to a function
> that should not be called twice.
>
> One way I can do this is to set some variable in the database when the
> form is submitted or one of several links clicked on a page and check
> whether it already is set and disallow new submits (or some such). However,
> I want to do this in many places and don't want to sprinkle all my code and
> database with names that I can't track. I tried to achieve this by defining
> a new variable in the request itself that I set to #false initially and
> then set! to true when any link is hit -- but this fails if a person comes
> back, refreshes the page and clicks the link, since this creates a new
> instance of the variable.
>
> Qualtrics surveys have this feature, but the way they implement it is (I
> think) by being single-page apps where the 'Next' button loads the new page
> content via an Ajax call. I don't see how to turn my current website into
> that without substantial rewrites.
>
> Cheers,
> Marc
>
> --
> 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/7e356eb4-e886-4f9c-90cd-0db658d14a91%40googlegroups.com
> <https://groups.google.com/d/msgid/racket-users/7e356eb4-e886-4f9c-90cd-0db658d14a91%40googlegroups.com?utm_medium=email_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/CABefVgzmMJMrqjAF4JXJU7txX9hU5HWBrfREP915j8ggi%3Dmt5w%40mail.gmail.com.


Re: [racket-users] FFI and immovable pointers for input/output (featuring automatic cropping for picts)

2019-09-19 Thread Jens Axel Søgaard
Den tor. 19. sep. 2019 kl. 17.05 skrev Matthew Flatt :

> I don't think you need immobile memory. There are no callbacks to
> Racket involved with `cairo_recording_surface_ink_extents`, and you're
> not using `#:blocking? #t`, so no memory-moving GC will happen during
> the foreign call. That means `_ptr` is fine.
>

Great.

Thanks,
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/CABefVgw_3wEtq6X9-YEOiwQDfthbOnzz54S-WuPAcp%2Bi92E_aA%40mail.gmail.com.


[racket-users] FFI and immovable pointers for input/output (featuring automatic cropping for picts)

2019-09-19 Thread Jens Axel Søgaard
Hi All,

I am working on automatic cropping for picts. Here automatic means the
pict will be cropped (or extended) to include what will be inked when the
pict is drawn.

The function crop/inked seems to work fine (see attached file), but the
functions in draw/unsage/cairo uses the following for outputs:

(define-fun-syntax _ptr/immobile
  (syntax-id-rules (_ptr/immobile o)
[(_ptr/immobile o t) (type: _pointer
pre:  (malloc t 'atomic-interior)
post: (x => (ptr-ref x t)))]))

Since I need both input and output I have used

(_ptr io _double)

but maybe I need to use a version of  _ptr/immobile that also handles io
arguments?

If so how can I change the definition of _ptr/immobile.

See attached file for `crop/inked`.

/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/CABefVgwQynBRMbthR4%3DsQQ7OUwOV9mjgpcGazqWtkeLX-di1ow%40mail.gmail.com.


crop-and-crop-inked.rkt
Description: Binary data


Re: [racket-users] Running Big Bang applications in the browser

2019-09-16 Thread Jens Axel Søgaard
Check WeScheme.

https://www.wescheme.org/

(forgot to send to the list first time around)

/Jens Axel

Den man. 16. sep. 2019 kl. 12.26 skrev Maciek Godek :

> Hi,
> is there any way to deploy Racket's big-bang applications to run in a
> browser (or any plans to enable that feature)?
>
> --
> 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/8ece7940-39d0-42a6-9ede-1ca2f9b071c1%40googlegroups.com
> <https://groups.google.com/d/msgid/racket-users/8ece7940-39d0-42a6-9ede-1ca2f9b071c1%40googlegroups.com?utm_medium=email_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/CABefVgykX2%3D6qsjkPo-_jmsfxgcgv5aQ20%2BJajKv9FcUnKO%2BYg%40mail.gmail.com.


Re: [racket-users] transparency in Pict

2019-09-10 Thread Jens Axel Søgaard
Den tir. 10. sep. 2019 kl. 17.04 skrev Hendrik Boom :

> On Tue, Sep 10, 2019 at 03:23:43PM +0200, Jens Axel Søgaard wrote:
>


> > I have extended "clipped" to handle regions defined by more than one
> path.
> > Now (clipped c ... p) will make a region from the curves c ... and use
> > the region to clip the pict p. Most common uses:
> >
> >(clipped c p)  the part of p inside c
> >(clipped c1 c2 p)   the part of p between c1 and c2 (if c2 is inside
> c1)
>
> Does that mean the part of p that is inside c1 and outside c2? (which
> would be meaningful even if c1 and c2 intersect?  That might happen
> because of numerical instability.)
>

Whether is point is inside or outside the region given by the
two curves is decided by the "winding rule". See the
discussion on fill (which also uses the winding rule):

https://docs.racket-lang.org/metapict/index.html?q=metapict#%28def._%28%28lib._metapict%2Fdraw..rkt%29._fill%29%29

For filling with the even-odd rule I have an eofill, but I haven't written
an eoclipped yet.

/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/CABefVgwxKrkbuqT_RbHtmX1Oda%2BEY_876naVT%2BQ5GJO2NWqxFQ%40mail.gmail.com.


Re: [racket-users] transparency in Pict

2019-09-10 Thread Jens Axel Søgaard
Den tir. 10. sep. 2019 kl. 14.54 skrev George Neuner :

>
> Or create a region with a hole through it and use it to clip the drawing.
>

Great suggestion. That's much better than using pict->bitmap.

I have extended "clipped" to handle regions defined by more than one path.
Now (clipped c ... p) will make a region from the curves c ... and use
the region to clip the pict p. Most common uses:

   (clipped c p)  the part of p inside c
   (clipped c1 c2 p)   the part of p between c1 and c2 (if c2 is inside c1)

The example now becomes:

#lang racket
(require metapict metapict/polygons)

(define (cutout p x y r)
  (defv (w h) (pict-size p))
  (with-window (window 0 w 0 h)
(clipped (rectangle (pt 0 0) (pt w h))
 (circle (pt x y) r)
 p)))

(set-curve-pict-size 400 400)
(def p (brushcolor "red" (fill (regular-polygon 5
(cutout p 200 200 50)

Before only one curve was supported and the result of clipped was the
interior,
so the old clipped couldn't cut holes.

/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/CABefVgzoXLWXnjjrJhzwyzPVgHpzW7gif%2BwN5WyGVWzb-FiB1w%40mail.gmail.com.


Re: [racket-users] transparency in Pict

2019-09-09 Thread Jens Axel Søgaard
You can use a path with an even-odd-fill to cut out parts.

An example:

#lang racket
(require metapict metapict/polygons)

(define (cutout p x y r)
  (defv (w h) (pict-size p))
  (with-window (window 0 w 0 h)
(brushstipple (pict->bitmap p)
  (eofill (rectangle (pt 0 0) (pt w h))
  (circle x y r)

(set-curve-pict-size 400 400)
(def p (brushcolor "red" (fill (regular-polygon 5
(cutout p 200 200 50)

/Jens Axel

The result (the yellowish color is the background color in my editor):

[image: image.png]


Den man. 9. sep. 2019 kl. 20.20 skrev Hendrik Boom :

> I'm wondering how to cut a transparent hole in something.
>
> Say I have a rectangle and I want to make part of it transparent so
> that I cn see what's behind it.
> Drawing a transparent rectangle on top of it won't workm because it'll
> just reveal the original rectangle.
> The only way I cn see it to draw the original rectangle in pieces,
> careful avoiding the area I want to make transparent.  (that may be
> tricky if the transparent area is, say, a circle).
>
> Is there some convenient operation in Pict that can accomplish this
> more directly?  Kind of the union and intersection and complementation
> on constructive solid geometry, but now 2D.
>
> My guess is no.  I haven't found it.  So I ask.
>
> Maybe I'll need some other drawing tool than Pict.  Suggestions welcome.
>
> -- hendrik
>
> --
> 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/20190909182018.74o322qfwehrmqaz%40topoi.pooq.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/CABefVgy0cxZD1dJv6dA51_rTEFqk3wu-zBSpGdQV-eD1fmurag%40mail.gmail.com.


Re: [racket-users] Downloadable tutorials (e.g. on github)? Tutorial example source codes samples attached to DrRacket instalation?

2019-09-09 Thread Jens Axel Søgaard
FWIW there a lot of (small) examples at

https://rosettacode.org/wiki/Category:Racket

/Jens Axel

Den man. 9. sep. 2019 kl. 16.09 skrev Prokop Hapala :

> Hi,
>
> I recently found Racket when I was searching some tutorials about Lisp and
> Metaprogramming. I really like that the community around DrRacket seems to
> be very much interested in education, making talks and tutorials even for
> childerens. The doc pages https://docs.racket-lang.org/ seems to be best
> what I found up to now in Lisp-world.
>
> What I'm missing however is some example codes which I can just simply
> download, load in DrRacket, run, and see what it does (without copying it
> step by step from doc-pages). This is my favourite way of learning -
> reverse-engineering finished cool demos. I don't like reading tutorials
> step-by-step. I like just browsing over code examples and see what is
> interesting.
>
> I was searching for some time to find some links e.g. to
> github-repositories with example codes for Racket, but I did not found
> almost anything usefull (easily accessible, easy to make i run).
>
> Maybe you know processing (https://processing.org/), it is in some
> aspects similar to DrRacket
>
>- It tries to bring programming to non-programmers (e.g. arts,
>humanities)
>- It has own minimalistic IDE to make it easier for people
>
> but unlike DrRacket it has huge amount of example codes packed within the
> standard instalation, (see attached picture). I think it would be great
> addition to DrRacket, exactly in direction of what you try to achieve.
>
> [image: Screenshot_2019-09-09_15-55-18.png]
>
>
>
>
>
>
>
>
>
>
>
>
> Other great thing which help me learn to program are
> https://www.shadertoy.com/
> https://www.openprocessing.org/
>
> ... it would be greate if something similar would be there for Racket,
> Lisp, Haskell or any of these kind of languages
>
> ( I come from graphics/physics background (imperative languages
> C/C++,GLSL,OpenCL ...  , high-performace), I have no previous experience
> with any Lisp-family language nor other functional language  )
>
> --
> 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/254a1ad3-637c-46d1-9466-3a10599af180%40googlegroups.com
> <https://groups.google.com/d/msgid/racket-users/254a1ad3-637c-46d1-9466-3a10599af180%40googlegroups.com?utm_medium=email_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/CABefVgy0r1Bbchy8FirQ46LN%3DyRNocXtaEsc3iVeV%2BxrR%2BNFfw%40mail.gmail.com.


Re: [racket-users] Listing All Programs

2019-09-05 Thread Jens Axel Søgaard
Den tor. 5. sep. 2019 kl. 23.27 skrev Josh Rubin :

>
> On 9/5/2019 9:05 AM, Adam Golding wrote:
> > What is the shortest/smallest racket program (ithat enumerates all and
> > only valid racket programs?
> >
>
> You might be interested in the logic-programming/constraint-solving
> language named miniKanren.
>
>
Apropos,  Friedman and Byrd shows how one can use an
interpreter written in Kanren to generate Scheme programs.

https://www.youtube.com/watch?v=5vtC7WEN76w

/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/CABefVgzYc0sMhobXpW9Ucbkpiex-45of6mAHSV_di4wiTc%2B_Gg%40mail.gmail.com.


Re: [racket-users] I'd like clarification about scribble and pollen.

2019-08-28 Thread Jens Axel Søgaard
Den ons. 28. aug. 2019 kl. 20.45 skrev Hendrik Boom :

>
> There is even a documented trick that enables a user to
> discover the s-expression resulting from a particular @-expression.
> But this trick does not show the s-expression resulting from an entire
> #lang scribble file.  Is there a way to see that?  Or have I got the wrong
> idea entirely?
>

Open your file in DrRacket. Click run. Now in the repl, evaluate  doc.

/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/CABefVgwQk-Z3%3DtHEGY2WSbP2-8B3GCKP70ZULZ1J618pAWZyNg%40mail.gmail.com.


Re: [racket-users] running the wrong sqlite3

2019-08-20 Thread Jens Axel Søgaard
And if you are on macOS:

mbp:metapict soegaard$ export DYLD_PRINT_LIBRARIES=1
mbp:metapict soegaard$ export DYLD_PRINT_LIBRARIES_POST_LAUNCH=1
mbp:metapict soegaard$ export DYLD_PRINT_RPATHS=1

/Jens Axel


Den tir. 20. aug. 2019 kl. 18.49 skrev 'John Clements' via Racket Users <
racket-users@googlegroups.com>:

> In that case, perhaps you can watch the calls to dlopen with strace? See
>
>
> https://stackoverflow.com/questions/5103443/how-to-check-what-shared-libraries-are-loaded-at-run-time-for-a-given-process
>
> for something that might be helpful.
>
> John
>
> > On Aug 20, 2019, at 11:30, James Platt  wrote:
> >
> >
> > On Aug 19, 2019, at 9:24 PM, John Clements wrote:
> >
> >> Perhaps you need to configure your lib-search-dir setting?
> >>
> >>
> https://docs.racket-lang.org/raco/config-file.html?q=lib-search-dir#%28idx._%28gentag._65._%28lib._scribblings%2Fraco%2Fraco..scrbl%29%29%29
> >
> > Thanks for the help but I think that's not the issue because
> (get-lib-search-dirs) returns exactly the same thing on a machine where
> this is working perfectly as on the machine where it isn't.  The machine
> where it is not working is a virtual machine with a stock install of macOS
> High Sierra and a relatively fresh install of Racket.  This VM is meant for
> development and testing.   This particular clone of the reference VM has
> been used for a little while but it should still be close to the
> reference.  So, on the one hand, it's surprising that this is happening
> here, with something so close to stock configuration.  On the other hand,
> the machine where it is working has been beaten into submission to run all
> kinds of development tools over a period of years.
> >
> > --
> > 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/91E6919B-7066-4550-B394-0FA66886A6B0%40biomantica.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/433b3b19-e6ef-43b6-957f-e58da37675f6%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/CABefVgy3R4mKShJksUa7QAh0aJrpqU94jTxPtBbW8tzYqC3RoA%40mail.gmail.com.


Re: [racket-users] Unwelcome surprises using Scribble on a 90,000-word novel

2019-08-02 Thread Jens Axel Søgaard
Den tor. 1. aug. 2019 kl. 13.25 skrev Hendrik Boom :

> (2) When I use include-section from the main file, the actual text in
> the main file appears first, and the included files are all saved up ane
> emitted after the text in the main file.  I expected the sections to be
> included where the include-section command was instead of being saved to
> the end.
>

Here is a typical example of how include-section is intended to be used:

https://github.com/racket/scribble/blob/master/scribble-doc/scribblings/scribble/internals.scrbl


The "main" file doesn't do anything, but use include other sections.
So a "solution" is to move the text you have in your main file into a
separate file.

And because I was curious, I looked up the defintion of  include-section:

(define-syntax (include-section stx)
  (syntax-case stx ()
[(_ mod)
 (with-syntax ([doc-from-mod (datum->syntax #'mod 'doc)])
   (unless (module-path? (syntax->datum #'mod))
 (raise-syntax-error #f "not a module path" stx #'mod))
   #'(begin
   (require (only-in mod [doc-from-mod doc]))
   doc))]))

So it does nothing but requiring the scribble file (which is a module
exporting  doc-from-mod).
It's renamed on import (because we might need to include several documents).
Then it is simply inserted into the document at the place  include-section
is used.

/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/CABefVgzTcXRy-fzdVMeDpyuUEn3qX6BP3T6keprpD_Sc8oBhYQ%40mail.gmail.com.


Re: [racket-users] Calling function with Scribble text as argument(s)

2019-07-30 Thread Jens Axel Søgaard
Den tir. 30. jul. 2019 kl. 19.02 skrev Hendrik Boom :

> I've found this as an example for getting coloured text:
>
> #lang scribble/base
>
> @(require scribble/core)
>
> @(define (colorize #:color c . content)
> (elem #:style (style #f (list (color-property c)))
>   content))
>
> @colorize[#:color "red"]{WARNING}
>
>
> But what if you want to call colorize from Racket code.
> For example, to make a function has the colour red built in,
> I tried
>
> @(define (redtext text) (colorize #:color "red" text))
>
> which did not work.
>

You are right that the contents isn't a single string, so change it to:

@(define (redtext . contents)
   (colorize #:color "red" contents))

@redtext{foo}

-- 
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/CABefVgyY1ED0HcbdXvvLGWxQO9j9AFBe99Db8uR16ieJL__J_A%40mail.gmail.com.


Re: [racket-users] Re: (ninth RacketCon) videos

2019-07-22 Thread Jens Axel Søgaard
>
>
> On Friday, July 19, 2019 at 12:19:44 PM UTC-7, Matthew Flatt wrote:
>>
>> Individual videos for this year's RacketCon talks are now available:
>>
>>  https://www.youtube.com/playlist?list=PLXr4KViVC0qJp4_2uTTAOjt-4URQBAR4c
>>
>
Den man. 22. jul. 2019 kl. 23.36 skrev Kees-Jochem Wehrmeijer <
henc...@gmail.com>:

> Thanks very much! Will your talk also be available Matthew? After all the
> racket2 talks it sparked here, I'm kind of curious.
>

It's available here:

https://www.youtube.com/watch?v=dnz6y5U0tFs

/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/CABefVgxpvXZg6Dqz-paDqzLAV6dOULKDOCxSsK6L1D2thQbyRA%40mail.gmail.com.


Re: [racket-users] Re: Thinking in scheme / racket

2019-07-11 Thread Jens Axel Søgaard
Den tor. 11. jul. 2019 kl. 15.40 skrev Bob Heffernan <
bob.heffer...@gmail.com>:

> On 19-07-11 09:31, James Geddes wrote:
> > Indeed, I would have thought that the calculation time would be
> > entirely dominated by the test for primality, and especially what
> > happens once the candidate primes are bigger than 2^64 and can no
> > longer be represented by a single word.
>


> I assume that you are right.  The isprime procedure in my python code is
> the one from sympy (I didn't bother to include the import line in my
> previous email).


I believe that sympy uses the C library GMP.


> The prime? procedure in my Racket code is that from
> the math/number-theory library.
>



> I don't know anything about sympy, but I seem to recall that Python
> libraries for these sorts of things often rely on fast routines written
> in C.  I suppose it might be interesting to implement the same
> prime-checking in both Python and Racket and *then* compare speeds.
>

If you want, you can use the prime test from GMP from Racket too.

#lang racket
(require gmp)

(define repetitions 25) ; manual says values between 15 and 50 are
reasonable.

(define (is-prime? n)
  (case (mpz_probab_prime_p (mpz n) repetitions)
[(2) #t]
[(1) 'probably]
[(0) #f]))

(for/list ([n (in-range 2 100)]
   #:when (is-prime? n))
  n)

See https://docs.racket-lang.org/gmp/index.html?q=gmp and
https://gmplib.org/manual/Number-Theoretic-Functions.html
 for more information.

/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/CABefVgxUZGtXUD8%2Bq5XS%3DTyQWO%2BWLgZNsm12LALbVviVPkwc-Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] Specializing functions accepting keywords

2019-07-10 Thread Jens Axel Søgaard
Consider the following fishy example wherein we try to
reuse a function with keyword arguments.


(define (fish #:name[name   #f]
  #:color   [color  #f]
  #:studio  [studio #f]
  #:eyes[eyes   2])
  (~a "The fish " name " is " color ", appears in a movie from " studio "
and has " eyes " eyes."))

Let's check see an example:

> (fish #:name "Nemo"   #:color "orange" #:studio "Disney")
"The fish Nemo is orange, appears in a movie from Disney and has 2 eyes."

A few examples later one quickly realizes that Disney has
a lot of fish in their movies:


(fish #:name "Nemo"   #:color "orange" #:studio "Disney")
(fish #:name "Dory"   #:color "blue"   #:studio "Disney")
(fish #:name "Marlin" #:color "orange" #:studio "Disney")
(fish #:name "Wanda"  #:color "gold"   #:studio "MGM")
(fish #:name "Blinky" #:color "orange" #:studio "Fox" #:eyes 3)


No worries, we can quickly define a  disney-fish  that simply
calls  fish  using the #:studio keyword and passes other keywords
along. The new  disney-fish must accept the same keywords as fish
(except for the studio one), so  procedure-reduce-keyword-arity
is needed to restrict the accepted keywords.


(define disney-fish
  (let ()
(define (make-disney-fish kws kw-args . rest)
  (keyword-apply/sort fish kws kw-args rest #:studio "Disney"))

(define-values (fish-required fish-allowed) (procedure-keywords fish))
(define fish-arity (procedure-arity fish)) ; number of by-position
arguments

(procedure-reduce-keyword-arity
   (make-keyword-procedure make-disney-fish)
   fish-arity
   (remove '#:studio fish-required)
   (remove '#:studio fish-allowed

Now we can write:

(disney-fish #:name "Nemo" #:color "orange")

The new  disney-fish  accepts only keywords accepted by fish,
so any error reporting works as expected.

But ... the above solution wasn't quick - it took more work than I
initially expected.
Am I missing something that makes reusing functions accepting
keyword arguments easier?

/Jens Axel


-- full example --


#lang racket

(require kw-utils/keyword-apply-sort)

(define (fish #:name[name   #f]
  #:color   [color  #f]
  #:studio  [studio #f]
  #:eyes[eyes   2])
  (~a "The fish " name " is " color ", appears in a movie from " studio "
and has " eyes " eyes."))

(fish #:name "Nemo"   #:color "orange" #:studio "Disney")
(fish #:name "Dory"   #:color "blue"   #:studio "Disney")
(fish #:name "Marlin" #:color "orange" #:studio "Disney")
(fish #:name "Blinky" #:color "orange" #:studio "Fox" #:eyes 3)

(define disney-fish
  (let ()
(define (make-disney-fish kws kw-args . rest)
  (keyword-apply/sort fish kws kw-args rest #:studio "Disney"))
(define-values (fish-required fish-allowed) (procedure-keywords fish))
(define fish-arity (procedure-arity fish)) ; number of by-position
arguments
(procedure-reduce-keyword-arity
 (make-keyword-procedure make-disney-fish)
 fish-arity
 (remove '#:studio fish-required)
 (remove '#:studio fish-allowed


(disney-fish #:name "Nemo" #:color "orange"
 #:studio "foo")

; Notes:
; > (disney-fish #:name "Nemo" #:color "orange" #:studio "Disney")
; correctly shows error (#:studio not expected)

-- 
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/CABefVgyXzWW1WJjC9SViyzsheswJD9Ek4LDfwqaNg_v4mT6y%3DQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] HTML rendering

2019-06-21 Thread Jens Axel Søgaard
Den fre. 21. jun. 2019 kl. 21.10 skrev James Platt :

> I've been looking at HTML rendering in Racket and the Browser package
> looks interesting, especially since it can execute Racket code from a
> special HTML tag.
>
> https://docs.racket-lang.org/browser/index.html
>
> The problem is that the rendering it does is too simple.  It's about on
> the level of Lynx and doesn't even render tables.


The browser package is mostly historical. It was used to browse
documentation inside DrRacket, but at some point
it made more sense to use an external web-browser.


> Is there another option that I am missing, like something implementing
> Gecko or KHTML/Webkit?

If not is there much interest in creating such a thing? The idea would be
> to be able to have a Racket GUI with a component implemented in HTML +
> CSS.
>

Using Webkit from within DrRacket would indeed be interesting.
Dobson made bindings for webkit at some point - but time flies by.

 https://github.com/endobson/racket-webkit

I know of no newer packages.

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


Re: [racket-users] for loop: any way to access the whole list?

2019-06-14 Thread Jens Axel Søgaard
I am not entirely sure this answer is what you are looking for, but the
following generator
will produce the pairs of the list instead of the elements.

(define (in-pairs xs)
  (make-do-sequence
   (λ ()
 (define (pos->element p) p)
 (define (next-position p) (cdr p))
 (define initial-position xs)
 (define (continue-with-pos? p) (pair? p))
 (values pos->element
 next-position
 initial-position
 continue-with-pos?
 #f #f

Example:

>* (for ([p (in-pairs '(1 2 3 4))])
*(displayln p))
(1 2 3 4)
(2 3 4)
(3 4)
(4)

So you can use

(define descriptions (list "this" "that"))
(define amounts  (list 4467.61 2428.37))
(for ([d descriptions] [ds (in-pairs descriptions)])
  [a amounts]  [as (in-pairs amounts])
   ...)

And use ds and as to get to other descriptions/amounts than the current
(which are in d and a).

/Jens Axel



Den fre. 14. jun. 2019 kl. 16.45 skrev Sanjeev Sharma :

> within this for loop is there any way to access different pieces of the
> description and amt?  car-ing and cdr-ing for example?
>
> Or move the identifier definitions into the let*, and pass those to for in
> some way?
>
> (let*((ratio 9/12))
>   (for((description(list "this" "that"))
>(amt(list 4467.61 2428.37)))
> (printf"~a ~a: changed values\n"
>description
>(cat(* amt ratio) -2.
>
> --
> 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/07ad5ce3-0ba8-48a5-a356-5cb1545de4cd%40googlegroups.com
> <https://groups.google.com/d/msgid/racket-users/07ad5ce3-0ba8-48a5-a356-5cb1545de4cd%40googlegroups.com?utm_medium=email_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>


-- 
-- 
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/CABefVgzj7eyxCpoq%3D3ULbeZ9-BsDkPj50RZa%3D-nhQxnf65u4rg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Re: How would you implement autoquoted atoms?

2019-04-23 Thread Jens Axel Søgaard
Yes, a global table of all existing keywords are needed.
I would do something along the lines of:

#lang racket
(struct Keyword (string))
(define global-keyword-hash (make-hash))

; keyword : string -> keyword
(define (keyword s)
  (define k (hash-ref global-keyword-hash s #f))
  (or k
  (let ()
(define k (Keyword s))
(hash-set! global-keyword-hash s k)
k)))

(eq? (keyword "a") (keyword "a"))
(eq? (keyword "a") (keyword "b"))
(eq? (keyword "b") (keyword "b"))


Den tir. 23. apr. 2019 kl. 15.22 skrev zeRusski :

> One thought that only just occurred to me is that we certainly want to
> allow creating kws dynamically, so a piece of code may generate some. IIUC
> this means it can no longer be a purely reader-based feature. Either reader
> and runtime have to communicate the global table somehow or the entire
> thing belongs at runtime save for actually parsing text. I wonder how
> taxing such implementation becomes. I feel like Racket keywords and
> interned symbols may have some lower language support that I can't access?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>


-- 
-- 
Jens Axel Søgaard

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] question about matching with "(? ...)"

2019-04-21 Thread Jens Axel Søgaard
Try

[rest (filter-odds rest]

as the last clause.

søn. 21. apr. 2019 kl. 22.19 skrev Tim Meehan :

> Forgive this naive question, I am having some trouble understanding some
> matching forms. If I wanted to filter out odd numbers like this:
>
> (filter odd? '(1 2 3 4 5)) => '(1 3 5)
>
> but I wanted to do this with a match:
> (define (filter-odds v)
>   (match v
> [empty empty]
> [(cons (? odd? first) rest) (cons first (filter-odds rest))]
> [_ (filter-odds rest)]))
>
> (filter-odds '(1 2 3 4 5)) => '(1 2 3 4 5)
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>
-- 
-- 
Jens Axel Søgaard

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] make extensions or replacements

2019-04-16 Thread Jens Axel Søgaard
Hav you tried the make library?

https://docs.racket-lang.org/make/index.html?q=make

Den tir. 16. apr. 2019 kl. 21.54 skrev :

> Hendrik,
>
> What is that you are trying to do, maybe you are misunderstanding some
> concept about make?
>
> It seems to me that the whole point of make is to "run a program"
> whenever
> some of the files have changed.
>
> Regards,
>
> David
>
> On 2019-04-16 21:25, Hendrik Boom wrote:
> > I'm sending this here, not because it's directly related to Racket,
> > nor because i think you all are experts in make or GNU make, but
> > because you are reasonable erudite in language appreciation.
> >
> > I, like many others, have been using a Makefile as a recipe to make a
> > lot of files from other files.
> >
> > The trouble is that a lot of the stanzas are quite repetitive.  I want
> > to refactor.
> >
> > If I were writing this in any other language then make,  i would just
> > define a function with about three or four short parameters and call it
> > many times, each time doing the equivalent of several of these stanzas.
> >
> > Roughly speaking, the abstraction tools of GNU Make are terrible.
> >
> > I'd like to ask you, what other tools might you actually recommend to
> > used in addition to make, or instead of it, that make the build
> > process more like normal programming?
> >
> > If I could get make to run a program to make another makefile and then
> > execute that new makefile, I suppose I could write the program that
> > makes all the repetitive (but not quite the same) stanzas.  But that
> > would likely make the build process somewhat obscure.
> >
> > Sure, I could invent something.  But chances are, someone else already
> > has invented something better than I'd improvise.
> >
> > -- hendrik
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>


-- 
-- 
Jens Axel Søgaard

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Pattern: reusing the same name in macro-generated definitions

2019-04-05 Thread Jens Axel Søgaard
Yes!

fre. 5. apr. 2019 kl. 13.52 skrev Hendrik Boom :

> On Fri, Apr 05, 2019 at 01:35:37PM +0200, Jens Axel Søgaard wrote:
> > Den tor. 4. apr. 2019 kl. 21.58 skrev zeRusski  >:
> >
> > (define-simple-macro (define-foo (name:id formal:id ...) body:expr ...)
> > >>   (begin
> > >> (define (foo-impl formal ...) body ...)
> > >> (define-syntax (name stx)
> > >>   (syntax-parse stx
> > >> [(_ . args) #'(foo-impl . args)]
> > >> [_:id #'(λ args (apply foo-impl args))]
> > >
> > >
> > >
> > >
> > >> (define-foo (bar op a b) (op a b))
> > >> (define-foo (baz op a b) (op a b))
> > >> ;; Why am I not getting this error?
> > >> ;; 
> > >> ; module: identifier already defined
> > >> ;   at: foo-impl
> > >
> > >
> > >
> > > See that *foo-impl* there? The same name is being reused every time the
> > > *define-foo* macro is called.
> > >
> > I would've expected Racket to shout at me that I'm attempting to redefine
> > > something, but it doesn't and magically it works.
> > >
> > Why?
> > >
> >
> > A simple model to keep in your head:
> >   Each macro keeps a count, i,  of how many times it has been applied.
> >   Each time a the output of a macro contains a definition of name not
> > present in the output it appends _i to the name.
>
> Do you mean not present in the *input*?
>
> -- hendrik
>
> >
> > Thus
> >   (define-foo (bar op a b) (op a b))
> > will define   foo_imp_1   and
> >   (define-foo (bar op a b) (op a b))
> > will define   foo_imp_2   respectively.
> >
> > Simple models do not explain all situations, but it does handle simple
> > situations.
> >
> > /Jens Axel
> >
> > --
> > You received this message because you are subscribed to the Google
> Groups "Racket Users" group.
> > To unsubscribe from this group and stop receiving emails from it, send
> an email to racket-users+unsubscr...@googlegroups.com.
> > For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>
-- 
-- 
Jens Axel Søgaard

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Pattern: reusing the same name in macro-generated definitions

2019-04-05 Thread Jens Axel Søgaard
Den tor. 4. apr. 2019 kl. 21.58 skrev zeRusski :

(define-simple-macro (define-foo (name:id formal:id ...) body:expr ...)
>>   (begin
>> (define (foo-impl formal ...) body ...)
>> (define-syntax (name stx)
>>   (syntax-parse stx
>> [(_ . args) #'(foo-impl . args)]
>> [_:id #'(λ args (apply foo-impl args))]
>
>
>
>
>> (define-foo (bar op a b) (op a b))
>> (define-foo (baz op a b) (op a b))
>> ;; Why am I not getting this error?
>> ;; 
>> ; module: identifier already defined
>> ;   at: foo-impl
>
>
>
> See that *foo-impl* there? The same name is being reused every time the
> *define-foo* macro is called.
>
I would've expected Racket to shout at me that I'm attempting to redefine
> something, but it doesn't and magically it works.
>
Why?
>

A simple model to keep in your head:
  Each macro keeps a count, i,  of how many times it has been applied.
  Each time a the output of a macro contains a definition of name not
present in the output it appends _i to the name.

Thus
  (define-foo (bar op a b) (op a b))
will define   foo_imp_1   and
  (define-foo (bar op a b) (op a b))
will define   foo_imp_2   respectively.

Simple models do not explain all situations, but it does handle simple
situations.

/Jens Axel

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] color-maps for the plot package

2019-03-22 Thread Jens Axel Søgaard
Looks great.


Den tor. 21. mar. 2019 kl. 14.01 skrev Alex Harsanyi :

>
> I created a pull request for items (1) and (2), illustrating the changes
> that I propose, you can find it here:
>
> https://github.com/racket/plot/pull/52
>
> Alex.
>
> On Wednesday, March 20, 2019 at 12:17:47 PM UTC+8, Alex Harsanyi wrote:
>>
>>
>>
>> On Wednesday, March 20, 2019 at 10:35:51 AM UTC+8, Ben Greenman wrote:
>>>
>>> > Could you (or Ben or Matt) elaborate on how do you see this work for
>>> non
>>> > plot programs?
>>>
>>> I'm thinking a color-map% object would define a possibly-infinite
>>> sequence of colors that look nice in some way. The colors might be
>>> useful anywhere where someone wants a "rainbow" of colors ... maybe
>>> for:
>>>
>>> - fonts in a slideshow (colorblind-friendly? grayscale-friendly?),
>>> - coloring the error messages made by a linter or program analyzer,
>>> - drawing a sunset, etc.
>>>
>>
>> The examples listed above might be better served by other color choosing
>> mechanisms, for example, I have implemented some color manipulation code
>> based
>> on https://tallys.github.io/color-theory/, you can find it here:
>> https://github.com/alex-hhh/data-frame/blob/master/private/colors.rkt .
>> In
>> particular the `pick-color` function might do something similar to what
>> Pyret
>> is using (as suggested by Justin Zamora).
>>
>> Other solutions are also possible, including using gradient color maps,
>> but
>> this is a larger scope that I originally planned for and I don't have
>> the time to prepare and submit a patch for such changes.
>>
>> My proposal is more limited, to allow plot users to produce good looking
>> plots
>> with minimum effort.  What I propose is:
>>
>> (1) Add a mechanism (via parameters) to replace the `pen-colors` and
>> `brush-colors` vectors in the plot package with custom defined colors.
>> This
>> means that the existing `->pen-color` and `->brush-color` functions would
>> now
>> return a different color depending on what `pen-colors` or `brush-colors`
>> are
>> installed.  This also has the benefit that the existing mechanism of
>> specifying numbers for colors will now work with color maps:
>>
>> (plot (list (function sin -5 5 #:color 1)))
>>
>> (2) "Borrow" the qualitative color maps from matplotlib, so the user has
>> some
>> nice predefined set of colors to choose from for their plots.
>>
>> Also, possibly the following backwards incompatible changes:
>>
>> (3) change the default set of `pen-colors` and `brush-colors` to one of
>> the
>> new color maps, so the nicer colors are on by default.
>>
>> (4) change the default plot behavior so that a different color is chosen
>> for
>> each renderer, this means that things like the code below would result in
>> different colors used for the `sin` and `cos` functions:
>>
>> (plot (list (function sin -5 5) (function cos -5 5)))
>>
>> If others think that (1) and (2) are worthwhile doing, I will submit a
>> PR, so
>> we can discuss the API an implementation over something more concrete.  I
>> am
>> open discussion for points (3) and (4).
>>
>> For the more broader color map changes, if the improvements are split up
>> in
>> small incremental tasks, I will be happy to help out, as time allows.
>>
>> Alex.
>>
>> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>


-- 
-- 
Jens Axel Søgaard

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] color-maps for the plot package

2019-03-20 Thread Jens Axel Søgaard
Den tir. 19. mar. 2019 kl. 23.03 skrev Alex Harsanyi :

> On Tuesday, March 19, 2019 at 9:53:23 PM UTC+8, Jens Axel Søgaard wrote:
>>
>> This is a great idea.
>>
>> It would be really nice to be able to use the colors also from non-plot
>> programs.
>>
>
> Could you (or Ben or Matt) elaborate on how do you see this work for non
> plot programs?
>

I would use it to draw graphs - but not using the built-in plot library.

/Jens Axel

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] color-maps for the plot package

2019-03-19 Thread Jens Axel Søgaard
FWIW see also the Mathematica documentation on ColorSchemes and related
functions for inspiration.

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


Re: [racket-users] color-maps for the plot package

2019-03-19 Thread Jens Axel Søgaard
This is a great idea.

It would be really nice to be able to use the colors also from non-plot
programs.

/Jens Axel






Den tir. 19. mar. 2019 kl. 08.09 skrev Alex Harsanyi :

>
> The Python matplotlib package supports the concept of a colormap for
> selecting
> colors for each data set that is displayed -- the user uses an index, like
> color 0, 1, 2, etc and this is mapped to a RGB value in the color map.  The
> visual aspect of a plot can be changed just by switching the color map.
>
> The color maps that are available to the matplotlib user have a nice set of
> colors chosen by experts (presumably) and this makes it easy to create nice
> looking plots, you can see the colors here:
>
> https://matplotlib.org/examples/color/colormaps_reference.html
>
> The `plot` library from Racket allows specifying colors by using the RGB
> triplet, or by using the `->pen-color` function which converts an index
> into a
> hardcoded set of colors -- this is similar to the color map concept, except
> that the available colors are not as nice and they are hardcoded:
>
>
> https://docs.racket-lang.org/plot/utils.html?q=-%3Epen-color#%28def._%28%28lib._plot%2Futils..rkt%29._-~3epen-color%29%29
>
> I would like to add support for color maps to the plot package, if others
> consider it worthwile.  The way I think it would work is that a new plot
> parameter (say `plot-pen-color-map`) would be defined and `->pen-color`
> would
> be changed to use the user specified color map instead of the default set
> of
> colors (the default set would still be used if no color map is specified).
>
> I put together some prototype code (including a screenshot of what it would
> look like) here:
>
> https://gist.github.com/alex-hhh/8ca14a0890dc2cfa8fc89e0c816d86da
>
> Technically this could be implemented outside the `plot` package, but I
> think
> it is much nicer to be readily available when Racket is installed and it
> will
> result in much nicer looking plots for a lot less effort.
>
> Do others think this would be useful?
>
> Alex.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>


-- 
-- 
Jens Axel Søgaard

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Cannot use case+else inside match+else

2019-02-27 Thread Jens Axel Søgaard
I suppose you could (re)require it again.

ons. 27. feb. 2019 kl. 14.19 skrev Laurent :

> Wait, that means that in an interactive session, if you ever happen to
> redefine `else', you can't use `case' anymore?
>
> On Tue, Feb 26, 2019 at 5:03 AM Ben Greenman 
> wrote:
>
>> Here's a suggestion for the docs:
>>
>> https://github.com/racket/racket/pull/2505
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Racket Users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to racket-users+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>
-- 
-- 
Jens Axel Søgaard

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Help with generators from python land!

2019-02-20 Thread Jens Axel Søgaard
Den ons. 20. feb. 2019 kl. 22.25 skrev Dave McDaniel :

> Hello,
>
> I have interest in picking up racket and have done some koans and also
> have been doing the racket track on exercism.
>
> There is a fairly simple exercise called `etl` on exercism related to
> taking a hash for scoring scrabble letters and unpacking it into a flatter,
> more efficient structure for lookups.
>
> The input hash has score as the key and a list of letters of that score as
> the value.  The output is a hash of letter -> score.  One pair per letter
> instead of one pair per score.
>
> It was easy enough to solve with `for-each` using side-effects to update a
> mutable hash, however I think using a generator is a cleaner approach and
> doesn't require mutability.
>

FWIW here is a solution using immutable hashes. I see `for` and friends as
Racket "generators".

/Jens Axel


#lang racket
(require racket/hash)

; In Scrabble each letter gives a certain number of points.
; In the old data we have for each point a list of numbers,
; that awarded the given number of points.

(define old-data
  ; list of associations from point to list of strings (letters)
  '((1  "A" "E" "I" "O" "U" "L" "N" "R" "S" "T")
(2  "D" "G")
(3  "B" "C" "M" "P")
(4  "F" "H" "V" "W" "Y")
(5  "K")
(8  "J" "X")
(10 "Q" "Z")))


; Each point list needs to be transformed to a
; hash table from letters to points.

(define (transform association)
  (match association
[(list point letters ...)
 (for/hash ([letter letters])
   (values (string-downcase letter) point))]))

; Now we only need to combine the hash lists.
(define ht
  (apply hash-union
   (hash)
   (for/list ([association old-data])
 (transform association

(define (lookup letter)
  (hash-ref ht letter #f))

(lookup "e")
(lookup "x")

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Wishlist for regexen: x mode, named captures, embeddable regexn

2019-02-14 Thread Jens Axel Søgaard
Den tor. 14. feb. 2019 kl. 16.16 skrev Greg Hendershott <
greghendersh...@gmail.com>:

>
> When I do use regexps in Racket, I almost always use them with `match`
> and the `pregexp` pattern, to bind the groups to identifiers.
>
> There is some space between trivial regexps and a full/"real" parser.
> Something like the `rx` macro, and it's also a match pattern, is
> something I could imagine using.
>

The lexer allows regular expressions in s-expression form.

https://docs.racket-lang.org/parser-tools/Lexers.html?q=lexer#%28form._%28%28lib._parser-tools%2Flex..rkt%29._lexer%29%29

It's not at easy to use as standard #rx and #px expressions though.

/Jens Axel

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Loading foreign libraries on Windows

2019-02-12 Thread Jens Axel Søgaard
FWIW here is the readme describing how to build libraries for Windows:

https://github.com/racket/racket/tree/master/racket/src/native-libs

Den tir. 12. feb. 2019 kl. 17.37 skrev George Neuner :

> Hi Philip,
>
> On 2/12/2019 1:18 AM, Philip McGrath wrote:
>
> I'm encountering an issue using `ffi-lib` to load a DLL on Windows. The
> problem appears to be specific to Racket, as I seem to be able to load the
> same DLL from Python.
>
> Specifically, I'm trying to build platform-specific packages for libgit2.
> I can build the library and run its test suite successfully, but when I try
> to load the DLL with `ffi-lib`, using an absolute path to avoid any search
> issues, it fails with the message "%1 is not a valid Win32 application.;
> errid=193". The AppVeyor build log is here
> <https://ci.appveyor.com/project/philipmcgrath/native-libgit2-pkgs/build/job/urfo34x53oh0fr4l>,
> and this is the Racket script
> <https://github.com/LiberalArtist/native-libgit2-pkgs/blob/linker-errors/tmp-w64-test.rkt>
> that fails to load the DLL. As I mentioned, I can load the DLL successfully
> with this Python script
> <https://github.com/LiberalArtist/native-libgit2-pkgs/blob/linker-errors/py-w64-test-tmp.py>
> .
>
> I'm not much of a Windows person, and I'm not sure what else to do to
> debug this.
>
>
> If it isn't a simple 32-bit/64-bit mismatch, then it could be a lot of
> things.  :-(
>
> Unlike *nix, Windows supports several different kinds of DLLs.  If the
> wrong setting are used to compile or link, a Windows DLL can behave very
> oddly ... including working in one context (Python), but not in another
> (Racket).
>
> You say you built the library from source?   I briefly looked at the
> source, but I'm not very familiar with cmake, and I don't see where the
> compile and link options are being defined.  Which compiler did you use and
> with what settings?
> [If they are defined in the project somewhere, you can just point me to
> the file(s).]
>
> George
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>


-- 
-- 
Jens Axel Søgaard

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Re: nested for loops and suggested alternatives

2019-02-10 Thread Jens Axel Søgaard
>
> Performance Warning: Indexing the elements of arrays created in untyped
>> Racket is currently 25-50 times slower than doing the same in Typed Racket,
>> due to the overhead of checking higher-order contracts. We are working on
>> it.
>
>
I have no idea how to improve that (the timings are old - perhaps it has
become better already).

/Jens Axel



-- 
-- 
Jens Axel Søgaard

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Guide and reference

2019-02-08 Thread Jens Axel Søgaard
Den ons. 6. feb. 2019 kl. 12.33 skrev James Geddes :

> There was a recent discussion on this list about the Racket guides and
> manuals. Without wishing to comment on the suggestions therein, I did want
> to say what I really, really like about the Racket documentation.
>
> There are two things. The first is that the Reference is — and I know this
> sounds odd — true: when I want to know something, I look it up in the
> Reference, and there I find the truth and the whole truth about the thing.
> I don’t know how this is made to happen, but I find it extraordinarily
> helpful. It’s not an intuitive explanation, or an analogy, or a description
> in vague language: it’s the truth. (And it’s organised very well so I know
> where to look.)
>
> The second thing I like is the concision of the Guide. It is readable, and
> may well contain intuitive explanations and ways to think about things, yet
> it does so with economy.
>
...

> Thank you to everyone who has worked on the documentation.
>

Very well put.

Besides the reference and the guide it would be wonderful to see a series
of tutorials.
We have some (on pict and the web-server), but more is better.

Given the recent discussion on the strengths of Racket, a tutorial on GUIs
would be nice.
Alex Harsanyi - are you persuadable?

Your blog is great:   https://alex-hhh.github.io/tags/racket.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.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Real-world examples of XML usage?

2019-02-04 Thread Jens Axel Søgaard
Den søn. 3. feb. 2019 kl. 05.57 skrev David Storrs :

> There was a discussion in another thread lately about various ways of
> representing XML.  It got me thinking, and I wanted to ask about
> people's practical experience.
>
> What projects have y'all done where XML was the best choice for a
> reason other than "because we needed to interoperate with a service
> that required XML"?
>
> I've never needed to use XML that much -- HTML and CSS for the
> browser, ...


If you count representations of HTML then I am fond of representing HTML as
Racket structures.
Combined with the at-syntax from Scribble one can write code that looks
like:

(define (html-flash-card)
  ; style: "border:1px solid black"
  @div[class: "col-md-6" ]{
@div[id: "flash-card-content"]{
  @div[id: "flash-card-question-container"]{
@div[id: "flash-card-question"]{
  @h2{Flash Card}
  @p{The name of the mathematical exponentiation operator?}
  @p{ $$ c = \sqrt{a^2+b^2} $$}}}
  @html-answer-box[]}})

The example is from

https://github.com/soegaard/urlang/blob/master/urlang-examples/quiz/quiz.rkt

The docs are here:
http://docs.racket-lang.org/html/index.html?q=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.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Python's append vs Racket's append and helping novices understand the implications

2019-02-03 Thread Jens Axel Søgaard
FWIW here is an overview over data structures in Racket:

https://stackoverflow.com/questions/27584416/in-racket-what-is-the-advantage-of-lists-over-vectors/27589146#27589146

/Jens Axel


Den søn. 3. feb. 2019 kl. 05.37 skrev Alex Harsanyi :

>
> I put together some notes about available data structures in Racket, with
> some performance considerations.  It needs more work, but perhaps it can be
> used as a starting point and it can be added to the Racket wiki, if/when
> others consider it adequate:
>
> https://gist.github.com/alex-hhh/3cc5690a7f9c74543dab6c11344e6202
>
> I didn't write a "Python to Racket" guide, because I don't really know
> enough about Python to write such a document, and I also think that a more
> generic document is simpler to maintain and can be used by people who come
> from other languages as well.
>
> I also tried to keep the document short, the aim being to provide a
> competent programmer who is new to Racket with a 5 minute overview to its
> data structures and some links to the starting points in the
> documentation.  We can add things to it, but I think it is better to keep
> it short rather than comprehensive in this case -- after all, there is the
> Racket Guide and Racket Reference and these documents contain all the
> details.  Perhaps new documents can be added to the wiki, exploring other
> topics in more detail.
>
> I did not mention `ralist` because (1) I have no experience with it, but
> more importantly (2) the package is not part of the Racket distribution and
> has to be installed separately.  I don't it reflects well on Racket if we
> tell people to install a separate package if they want an efficient
> container...  I have no experience with `ralist`, but if it is indeed a
> good data structure and it has a potentially wide usage, it should be
> included in the default Racket installation.
>
> Alex.
>
> On Sunday, February 3, 2019 at 7:00:10 AM UTC+8, Matthias Felleisen wrote:
>>
>>
>>
>> Racket needs *you*. Please.
>>
>> The proper approach is to have short pages for different language
>> immigration groups: Python and R come to mind as obvious examples but I am
>> sure there are others.
>>
>> What I mean is we need help and *you* can help. Let me explain it with
>> the Python example:
>>
>> 1. Set up a page (wiki?) called “From Python to Racket”
>>
>> 2. Create two sections that are immediately visible from the top:
>>
>> — idioms
>> — performance pitfalls
>>
>> 3. In the specific case of Python, the second subsection needs to start
>> with a subsection on
>>
>> — Python Lists aren’t Racket Lists
>> — then point to data/ralis and show how to transliterate the
>> loop/append example like this
>> — optionally also show the more native Racket idiom
>>
>> 4. When anyone observers another blog/social media/whatever post on
>> Racket is slow because I come from Python,
>>
>> (a) point the posters to the page  or
>> (b) if it is a new case, write a section for this example then do
>> (a)
>>
>>
>> If you want to help advertise Racket to others, this is an excellent way
>> of helping out.
>>
>> Thanks — Matthias
>>
>> [[ p.s. For my very first Python program (a couple of days before meeting
>> with GvR), I used Python’s append and was annoyed beyond belief. ]]
>>
>>
>> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>


-- 
-- 
Jens Axel Søgaard

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Beginning of the end for googlegroups?

2019-01-29 Thread Jens Axel Søgaard
How many users are on the racket-users list?

Are we anywhere near the listed numbers?

Den lør. 26. jan. 2019 kl. 01.01 skrev 'Paulo Matos' via Racket Users <
racket-users@googlegroups.com>:

> Apologies for message unrelated to racket, but it might affect us.
>
> Just read this:
>
> https://groups.google.com/a/isocpp.org/forum/m/#!msg/sg14/FZEWCOSyFlk/MFUXyq1YDAAJ
>
> Not sure of the size of the mailing list but I wonder if this is the
> beginning of the end and we should have instead a plan B.
>
> --
> Paulo Matos
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>


-- 
-- 
Jens Axel Søgaard

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Problem controlling macro expansion

2019-01-27 Thread Jens Axel Søgaard
Den søn. 27. jan. 2019 kl. 22.06 skrev Jonathan Simpson :

> I'm having macro troubles with a DSL I'm writing. I have a macro that
> looks something like this:
>
> (define-syntax (query stx)
>   (let ([lines (cdr (syntax->datum stx))])
> (define lines-syntax-tree (parse-to-tree lines))
> (datum->syntax stx lines-syntax-tree)))
>

You are throwing away all location informations in the call `(syntax->datum
stx)`.
Consider using `(syntax->list stx)` instead.

/Jens Axel

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Weird behavior when a ‘set’ is the result of ‘eval’

2019-01-10 Thread Jens Axel Søgaard
A `set` is represented as a set structure. Structures are generative, so
each instantiation of the set structure gives you different structure types
(even though names and fields are identical). Creating a new namespace
means you get different set structures.

A hash is not represented as a structure, so you will not see a difference
there.

You can solve the problem with two different set structures by attaching
the original instantiation of the set module to your new namespace.

tor. 10. jan. 2019 kl. 17.50 skrev 'Leandro Facchinetti' via Racket Users <
racket-users@googlegroups.com>:

> Please help me understand the following:
>
> #lang racket
> (define s (eval '(begin (require racket/set) (set 1 2))
> (make-base-namespace)))
> s ;; ⇒ (set 1 2)
> (set? s) ;; ⇒ #f (but I expected ‘#t’)
>
> --
> Leandro Facchinetti 
> https://www.leafac.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.
> For more options, visit https://groups.google.com/d/optout.
>
-- 
-- 
Jens Axel Søgaard

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Re: Functional augmenting

2019-01-08 Thread Jens Axel Søgaard
Den tir. 8. jan. 2019 kl. 21.40 skrev David Storrs :

>
> This.  In an ideal world, before/after/around would be parameterized so
> that you can make the change only for a defined scope.
>
Still, the intent was never that it would extend its effects outside the
> current module.
>

In that case you can use let-syntax and to redefine #%app.

/Jens Axel

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


  1   2   3   4   >