[racket-users] OpenGL: (lack of) progress report

2020-04-11 Thread Hendrik Boom
I'm (still) building the up-to-date opengl binding for Racket.

It's substantially more difficut than I thought.

As some of you know, the existing OpenGL binding is generated from files 
supplied by the standards orgaisation Khronos.

Being automatically gnerated, it was quite complete.

However, it is obsolete.  Even the first simple exercises from the
authoritative so-called Red Book can no longer be translated into 
Racket.

I undertook to update it, planning to simply rerun the same code on the 
current version of the Khronos files.

Didn't work, because those files have not been updated.
Instead they have been replaced with new files satisfying the same 
purpose, but in a completely different file format -- xml.

The old code no longer works on the new files.

Since I really wanted to use up-to-date OpenGL, I resolved to write a 
new transpiler, from the new Khronos file format to the same old Racket 
language.

I thought I would just have to replace the parser in the previus opengl 
version.

I expected that debugging would be feasible by comparing the files I 
generate with the files generated by the old opengl package.  Most of 
the content should be identical.

(this last generated bit at least, has turned out to be true!)

I was faced with several challenges:

* Really learning Racket.  Up to now I've just been coding around the 
edges of Racket so to speak.  I like the language.  And despite running 
in an interpreter, that's Ok for computation-intensive graphics work 
because most of the computation gets passed off to a separate processor, 
the GPU.

* Figuring out the poorly documented code in the otherwise excellent 
original version of the transpiler.

* learning OpenGL.  I've used it before, but the arrival of shaders has 
completely turned it inside-out.

* Deciphering the Khronos files.  The XML isn't much of a barrier -- 
Racket's sxml package does the heavy lifting.

However, Khronos's use of xml doesn't have much to do with *any* current 
undersanding of programming language semantics.  Its xml syntax doesn't, 
for example, understand that functions have function types.

Instead, the declaration of a function is split into two separate parts: 
a prototype and some parameters.  The prototype contains the function 
name and its return type, together with a few random extras such as 
asterisks.

An asterisk is there to indicate that the function doesn't return the 
indicated type, but a pointer to it.  But there's no syntactic 
understanding that there's such a thing as a pointer type, and that the 
abstract syntax for a pointer type should contain the thye of the thing 
pointed to.

Similarly, there's no concept of a function type.

It's kind of a transcription of C.

---

So, given all that, I've been flailing around with my code, managing to 
produce a lot of mostly correct binding.

That's, of course, not good enough.

What has happened is that I'm starting to understand the obstacles that 
have to be overcome.

And that's a huge help in figuring out the original versino of the 
transpiler.

My original plan of replacing the parser in the original version is 
starting to seem feasible now.  However, properties of the original 
syntax reach far into the innards of its code generator.

I'm not giving up.  I will proceed.

What I'll likely end up with is some kind of amalgam of the old code and 
parts of the new code I've already written.

There will be success, unless I come down with coronavirus and die 
first.

-- 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/20200411153018.jju2lwh5fsgsmust%40topoi.pooq.com.


[racket-users] typed mutable fields in structures.

2020-04-11 Thread Hendrik Boom
I noticed that in regular Racket, when defining a structure, it is 
possible for each field to be mutable independent of the other fields.

In Typed Racke I find the choice only of making all the fields or none 
of them mutable.

Is this correct, or have I missed something?

-- 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/20200411141747.ijbhuadzsy5r56ge%40topoi.pooq.com.


Re: [racket-users] typing variable length argument lists

2020-04-11 Thread Hendrik Boom
On Fri, Apr 10, 2020 at 08:18:38PM -0400, Jon Zeppieri wrote:
> (define (unique [list : (Listof Any)] [message : String] .
> [messageargs : Any *])
>   ; return the only element of the list, or '() if there is none.
>   ; Produce message if not just one.
>   (if (equal? 1 (length list)) (car list)
>  (begin
>(apply fprintf anomaly message messageargs)
>(if (null? list) list (car list)

Thank you.  That worked.
The change to the apply syntax surprised me.

-- hendrik

> 
> On Fri, Apr 10, 2020 at 7:49 PM Hendrik Boom  wrote:
> >
> > Trying to convert the following to typed Racket:
> >
> > (define (unique list message . messageargs)
> >   ; return the only element of the list, or '() if there is none.
> >   ; Produce message if not just one.
> >   (if (equal? 1 (length list)) (car list)
> >  (begin
> >(apply fprintf (cons anomaly (cons message messageargs)))
> >(if (null? list) list (car list))
> >)
> >  )
> > )
> >
> > It's an error message function tat accepts a list to test.
> > If the test fails it uses fprintf to print a message with the
> > arguments for the ~s items.
> >
> > I got so far, but I don't know what to do with the . messageargs :
> >
> > (define (unique [list (Listof Any)] [message : String] . messageargs)
> >   ; return the only element of the list, or '() if there is none.
> >   ; Produce message if not just one.
> >   (if (equal? 1 (length list)) (car list)
> >  (begin
> >(apply fprintf (cons anomaly (cons message messageargs)))
> >(if (null? list) list (car list))
> >)
> >  )
> > )

-- 
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/20200411134316.yff5tg7kwtglcs62%40topoi.pooq.com.


[racket-users] Re: plotting multiple data sets on one set of axes

2020-04-11 Thread Alex Harsanyi

The renderers  that you pass on to the `plot` function can be manipulated 
outside the call to plot, so you can read the datasets you need, construct 
a renderer for each one, group them in a list and pass them on to plot.  I 
am not familiar with Matlab, but based on your description, you can 
implement hold-on and hold-off as follows:

#lang racket
(require plot)

(define the-renderers '())

(define (hold-on renderer)
  (set! the-renderers (cons renderer the-renderers)))

(define (hold-off)
  (begin0
(plot (reverse the-renderers))
(set! the-renderers '(

;; add a renderer for SIN
(hold-on (function sin 0 10))

;; add a renderer for COS
(hold-on (function cos 0 10))

;; Show the plot
(hold-off)

Alternatively, if you want a separate plot for each function, you can 
implement hold-off as follows:

(define (hold-off-2)
  (begin0
(for/list ([renderer (reverse the-renderers)])
  (plot renderer))
(set! the-renderers '(

Alex.

On Thursday, April 9, 2020 at 2:35:04 PM UTC+8, greadey wrote:
>
> Hi All,
>
> Can anyone give me some pointers on plotting multiple data sets on one set 
> of axes.  Plotting two or more data sets on one set of axes is easy if you 
> know in advance what the data is called;
>
> (plot (list
>   (lines set1)
>   (points set2))
>  #:x-label "x" #:y-label "y")
>
> however I have a list of data sets generated from reading a bunch of files 
> in a directory and I wish to loop through the list and add each data-set to 
> an existing set of axes.
>
> Iterating through the data and plotting each set results in multiple plot 
> windows.
>
> In summary I am looking for something similar to Matlab's "hold on" e.g.
>
> ;Pseudo Matlab code
>
> figure()
> for idx = 1 : numel(list-of (list-of vector-pairs))
> plot(list-of (list-of vector-pairs))(idx)
> hold on
> end
> hold off
>
> I have got (plot-new-window? #t), however as far as I know this is just 
> causing a plot to appear in a new window rather than directly in the repl.
>
> Many thanks,
>
> greadey.
>

-- 
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/ec890e78-b254-4e7e-9970-6f0d46f50c20%40googlegroups.com.


Re: [racket-users] Starting a language after Beautiful Racket

2020-04-11 Thread Pratyush Das
Thanks!

On Sat, 11 Apr 2020 at 00:12, Matthew Butterick  wrote:

> Three options:
>
> 1) Implement your language in `#lang br` now (and optionally convert to
> `racket/base` later) [1]
>
> 2) Import the `br/datum` module into a `#lang racket/base` program to get
> `format-datum` [2]
>
> 3) Reimplement `format-datum` your own way. You can see the underlying
> code by right-clicking on `format-datum` in DrRacket and selecting "Open
> Defining File".
>
> [1] https://beautifulracket.com/appendix/from-br-to-racket-base.html
> [2]
> https://docs.racket-lang.org/br/index.html?q=br%2Fdatums#%28mod-path._br%2Fdatum%29
>
> On Apr 10, 2020, at 9:17 AM, Pratyush Das  wrote:
>
> A followup question -
>
> But this assumes that the br lang is being used(I think because of the
>> format-datum syntax). How do I implement this without using the br lang?
>
>
> ...
>
> (define 
> 
>  src-lines (port->lines 
> 
>  port))
>   (define 
> 
>  src-datums (format-datums 
> 
>  '(handle ~a) src-lines))
>
> ...
>
>
> Is it possible to use modules to just get the format-datums from the br
> language?
>
>
> On Fri, 10 Apr 2020 at 17:50, Pratyush Das  wrote:
>
>> I am absolutely new to both Racket and language implementation.
>>
>> I read through some portions of Beautiful Racket
>>  and the racket guide
>>  before trying to
>> implement a language on my own and this is what I understand -
>>
>> I created a main.rkt which would be the boot module in my source
>> directory, following the Beautiful Racket master recipe
>> .
>>
>> Every language should define and provide a read-syntax function.
>>
>> To make the new language read the source file, read-syntax must be
>> defined something like -
>> (define (read-syntax path port)
>> ...)
>>
>> Like in Beautiful Racket's wires language implementation
>> , I want to read the
>> source file line by line and wrap it in a macro.
>> Beautiful Racket does it like this -
>>
>>   (define 
>> 
>>  (read-syntax 
>> 
>>  path port)(define 
>> 
>>  wire-datums  (for/list 
>> 
>>  ([wire-str (in-lines 
>> 
>>  port)])(format-datum 
>> 
>>  '(wire ~a) wire-str)))
>>
>>
>> But this assumes that the br lang is being used(I think because of the
>> format-datum syntax). How do I implement this without using the br lang?
>>
>> Also, am I wrong in any of my assumptions so far?
>>
>>
>>
>> --
>> You received this message because you are subscribed to a topic in the
>> Google Groups "Racket Users" group.
>> To unsubscribe from this topic, visit
>> https://groups.google.com/d/topic/racket-users/qEXz8YcAisc/unsubscribe.
>> To unsubscribe from this group and all its topics, 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/180aae4b-9e79-43cc-9177-6c917acf0dc8%40googlegroups.com
>> 
>> .
>>
>
>
> --
> Pratyush Das(Reik)
>
> --
> 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/CAFzLTskQ70okYZj247VA2rGNWyoW62wCyyu3jqXHtzZdw3aJEg%40mail.gmail.com
> 
> .
>
>
>

-- 
Pratyush Das(Reik)

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