[racket-users] Lambda calculus done in Racket

2020-02-17 Thread Lawrence Bottorff
I found these blowing down the sidewalk today

; TRUE = λx.λy.x
(define mytrue
  (lambda (t) (lambda (f) t)))

and

; FALSE = λx.λy.y
(define myfalse
  (lambda (t) (lambda (f) f)))

Two problems, I don't understand them and AFAICT, they don't work. I traced
them back to this

post on stackoverflow. Can anyone get me started here?

LB

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


Re: [racket-users] Science graphics with Racket?

2017-10-23 Thread Lawrence Bottorff
This is amazing! Thank you very much!

On Mon, Oct 23, 2017 at 4:49 PM, Jens Axel Søgaard <jensa...@soegaard.net>
wrote:

> I forgot to show how to make a graph.
>
> #lang racket
> (require racket/draw metapict metapict/graph)
>
> (set-curve-pict-size 300 300)  ; width and height of image
> (ahlength  1.0); size of arrow head
>
> (define (f x) (sin x))
>
> (define p
>   (with-window (window -12 12 -12 12) ; xmin, xmax, ymin, ymax
> (draw (draw-arrow (curve (pt -10   0) -- (pt 10  0)))  ; x-axis
>   (draw-arrow (curve (pt   0 -10) -- (pt  0 10)))  ; y-axis
>   (label-rt  "x" (pt 10.2 0))  ; label for x
> axis
>   (label-top "y" (pt 0 10.2))  ; label for y
> axis
>   (color "blue" (draw (circle (pt 2 1) 3))); center (2,1)
> radius 3
>   (color "red"  (draw (graph f -10 10 #:samples 50))
>
> p ; show pict in repl
>
> (define (save-pict-as-svg p width height filename [exists 'replace])
>   (define dc (new svg-dc%
>   [width width]
>   [height height]
>   [output filename]
>   [exists exists]))
>   (send dc start-doc "An SVG Test")  ; a message
>   (send dc start-page)
>   (draw-pict p dc 0 0)
>   (send dc end-page)
>   (send dc end-doc))
>
>
>
> (save-pict-as-svg p 300 300 "output.svg")
>
>
> 2017-10-23 21:39 GMT+02:00 Jens Axel Søgaard <jensa...@soegaard.net>:
>
>> Here is how to do it using MetaPict:
>>
>> #lang racket
>> (require racket/draw metapict)
>>
>> (set-curve-pict-size 300 300)  ; width and height of image
>> (ahlength  1.0); size of arrow head
>>
>> (define p
>>   (with-window (window -12 12 -12 12) ; xmin, xmax, ymin, ymax
>> (draw (draw-arrow (curve (pt -10   0) -- (pt 10  0)))  ; x-axis
>>   (draw-arrow (curve (pt   0 -10) -- (pt  0 10)))  ; y-axis
>>   (label-rt  "x" (pt 10.2 0))  ; label for x
>> axis
>>   (label-top "y" (pt 0 10.2))  ; label for y
>> axis
>>   (circle (pt 2 1) 3   ; center (2,1)
>> radius 3
>>
>> p ; show pict in repl
>>
>> (define (save-pict-as-svg p width height filename [exists 'replace])
>>   (define dc (new svg-dc%
>>   [width width]
>>   [height height]
>>   [output filename]
>>   [exists exists]))
>>   (send dc start-doc "An SVG Test")  ; a message
>>   (send dc start-page)
>>   (draw-pict p dc 0 0)
>>   (send dc end-page)
>>   (send dc end-doc))
>>
>>
>>
>> (save-pict-as-svg p 300 300 "output.svg")
>>
>>
>> 2017-10-23 21:04 GMT+02:00 Lawrence Bottorff <borg...@gmail.com>:
>>
>>> I'd like to use Racket to generate scalable (svg?) graphics like gnuplot
>>> or GeoGebra does. For example, I'd like to create a cartesian coordinate
>>> graph system, then draw functions on it. One thing in particular would be
>>> to draw a graph of a circle based on the standard form of a circle, e.g.,
>>> x^2 + y^2 = r^2. Again, I'd prefer being able to create an svg file. Is
>>> there a tutorial that might give me more insight than the reference pages
>>> or the Quick: An Introduction to Racket with Pictures? Or am I barking up
>>> the wrong tree?
>>>
>>> LB
>>>
>>> --
>>> 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
>>
>>
>
>
> --
> --
> 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.


[racket-users] Science graphics with Racket?

2017-10-23 Thread Lawrence Bottorff
I'd like to use Racket to generate scalable (svg?) graphics like gnuplot or
GeoGebra does. For example, I'd like to create a cartesian coordinate graph
system, then draw functions on it. One thing in particular would be to draw
a graph of a circle based on the standard form of a circle, e.g., x^2 + y^2
= r^2. Again, I'd prefer being able to create an svg file. Is there a
tutorial that might give me more insight than the reference pages or the
Quick: An Introduction to Racket with Pictures? Or am I barking up the
wrong tree?

LB

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


[racket-users] Is this a closure?

2017-04-20 Thread Lawrence Bottorff
Looking at HTDP-1 
(http://htdp.org/2003-09-26/Book/curriculum-Z-H-25.html#node_chap_19), I see 
this:

(define (filter predicate alon)
  (cond
   [(empty? alon) empty]
   [else (cond
  [(predicate (first alon)) 
   (cons (first alon)
 (filter predicate (rest alon)))]
  [else
   (filter predicate (rest alon))])]))

Then to find if a member of a list l is below a number i

(define (below i l) 
  (local ((define (below-i x)
(> i x)))
(filter below-i l)))

As the proverbial beginner -- who doesn't totally understand closures -- this 
looks like a use of the closure idea. Right? The i is "magically" known in 
`filter`, which seems pretty closure-ish to me. Or am I totally wrong?

LB

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


[racket-users] Racket/Dr. Racket on Android?

2017-04-20 Thread Lawrence Bottorff
Is there a version of Racket for Android yet?

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


Re: [racket-users] foldl reverses lists?

2017-04-19 Thread Lawrence Bottorff
Yes, thank you both for your help.

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


[racket-users] foldl reverses lists?

2017-04-19 Thread Lawrence Bottorff
I see this:

> (foldl cons '() '(1 2 3 4))
'(4 3 2 1)

and have to conclude that foldl is reversing the list. This is bolstered by 
this:

(define (my-reverse lst)
  (foldl cons empty lst))

which is a way of reversing a list. Good. But then I see this:

(foldl (lambda (a b result)
 (begin
   (printf "a: ~a, b: ~a, result: ~a\n" a b result)
   (* result (- a b
   1
   '(0 2 4 6)
   '(3 4 5 6))

giving this:

a: 0, b: 3, result: 1
a: 2, b: 4, result: -3
a: 4, b: 5, result: 6
a: 6, b: 6, result: -6
0

and I'm not seeing any reversal, right? The input 

1
'(0 2 4 6)
'(3 4 5 6)

seems to only be putting the result variable first. Or am I missing something?

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


[racket-users] Typed Racket error in REPL but not when command-line-loaded

2017-04-18 Thread Lawrence Bottorff
I'm looking at this from 
https://github.com/dparpyani/99-Lisp-Problems-in-Racket:

#lang racket
(require typed/racket)

;; Question:
;;   Find the last box of a list.
;;Example:
;; (my-last '(a b c d))
;;  => '(d)

;; Consumes a list and returns the last element in it.
(define (my-last lst)
  (cond
[(or (empty? lst) (empty? (rest lst))) lst]
[else (my-last (rest lst))]))

;; Tests
(assert (equal? (my-last `(a b c d)) `(d)))
(assert (equal? (my-last `(1 2 3 4)) `(4)))
(assert (equal? (my-last `((a b) (c d))) `((c d

...which seems to behave fine when loaded from the command line, i.e., 

#> racket Q01.rkt
#t
#t
#t

However, when loaded from with a Racket REPL
> (load "Q01.rkt")
> (my-last '(1 2 3))
; readline-input:14:1: Type Checker: missing type for top-level identifier;
;  either undefined or missing a type annotation
;   identifier: my-last
;   in: my-last
; [,bt for context]

Likewise, simply entering everything in the REPL also fails:

> (require typed/racket)
> (define (my-last lst)
(cond
  [(or (empty? lst) (empty? (rest lst))) lst]
  [else (my-last (rest lst))]))
; readline-input:18:30: Type Checker: Polymorphic function `rest' could not be
;   applied to arguments:
; Domains: (Listof a)
;  (Pairof a (Listof b))
; Arguments: Any
;   in: (rest lst)
; [,bt for context]

Why the different behaviors? All I'm trying to do is use assert. But then how 
would I change this code to be typed Racket?

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


Re: [racket-users] Re: Racket graphics?

2017-01-14 Thread Lawrence Bottorff
This is all very impressive, indeed. I was wondering if Racket could be used to 
create a new sort of GIS app, i.e., geographic information system. It would 
have to do "vector graphics," which is to say every primitive drawing object is 
real, i.e., isn't just a setup step toward creating a raster bit map -- to be 
thrown away afterwards. For example, if you use a square object to represent a 
building, then that object should persist as something real, to which various 
attributes can then be attached, furthermore, to be part of a graph database. 
On the UI side, the objects should be "clickable," i.e., an actual object 
should be addressed. The bitmap idea of clicking on a spot -- connecting spot 
with coordinates, then with other data -- won't do.

Also, are these links listed in your responses done in Scribble?

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


[racket-users] Racket graphics?

2017-01-13 Thread Lawrence Bottorff
I've seen Racket graphics doing some basic graphics. How expressive is it? 
Could it do diagrams as well as TikZ or gnuplot? What output formats are there? 
Could it be like Processing and do 3-d and motion?

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


[racket-users] Re: Good Data Structures Book?

2016-12-14 Thread Lawrence Bottorff
On Wednesday, December 14, 2016 at 12:19:51 PM UTC-5, Prabhakar Ragde wrote:
> 
> I am developing such a course for a spring term (May-August) offering at 
> the University of Waterloo (though it will probably use OCaml). There 
> does not appear to be an ideal textbook; I plan to synthesize materials. 
> There are FP books which cover some of the material in various 
> languages: Simon Thompson's Haskell book, Algorithms by Rabhi and 
> Lapalme (also Haskell), Larry Paulson's ML book. (In my opinion, Okasaki 
> and Bird are too advanced for a first DS course.) Mark Allen Weiss's DS 
> book in C is the best conventional book I have found; it is not afraid 
> of recursion.
> 
> One issue is that an early FP approach may well cover some topics from a 
> typical DS course, since it is possible to do so earlier. Examples from 
> my own experience include various sorting algorithms, O-notation and 
> algorithm analysis, various heap implementations of priority queues, 
> treaps, AVL trees, RB trees, AA trees, tries, and KMP text search. I 
> have covered these in various incarnations of first-year Racket courses 
> (not all at once).
> 
> I'd be happy to consult if you are considering developing a course. --PR

Yes, I have the Paulson book "ML for the Working Programmer," which mixes in 
some data structure, but nothing so thorough as Weiss. Then there is Okasaki's 
"Purely Functional Data Structures," which lives solely in the purely 
functional land of ML and Haskell and can't really be brought out very easily 
or so it seems to me. Anyway, it was a dissertation, which is inappropriate for 
undergrads. The other books mentioned aren't for weak of heart grad students, 
let alone undergrads. I find it ironic that I can search Racket docs on 
virtually any data structure and find a library ready and waiting. Maybe 
whoever did all those libraries should be volunteered into writing a textbook? 
(Laughter.) In general, I'm sure that between Weiss and Okasaki's "Purely 
Functional Data Structures" would be a nuanced Racket/TR way of doing things 
(macros, combinators, etc.). I'm personally not that good at Racket to know the 
"Enlightened Way," but it would be a good thing to have, no doubt.

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


[racket-users] Good Data Structures Book?

2016-12-13 Thread Lawrence Bottorff
Can someone suggest a good text for data structures that would compatible with 
Racket? All I see are treatments using C/C++, Java, Python, i.e., the usual 
suspects. Or, how do you people at Racket-friendly/based universities teach 
undergrad data structures?

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


[racket-users] Literate program a math course with Racket?

2016-11-28 Thread Lawrence Bottorff
I'm tackling SICP -- using Racket and Emacs/orgmode, which I think is the best 
combination (YMMV). I like SICP because it puts computational math in the mix 
of learning functional programming. Then Sussman did SICM (...Classical 
Mechanics; 2nd edition) -- which is way over my head. But again, it is the 
spirit of literate programming where the math and coding are combined, i.e., 
you don't sit in the vacuum of theory only, but code what you're learning.

But on the other hand, there are all the math packages: Maxima, Matlab, 
Mathematica, etc., where the programming has been done, or they want you to do 
code snippets in their own blub syntax. Most computational texts use these.

So is there anyone doing what Sussman and Wisdom did with SICM? For example, 
how would you do derivatives and integration and differential equations in 
Racket? A while back I found Steven L. Tanimoto's "The Elements of Artificial 
Intelligence
Using Common Lisp," which had some basic POC derivative-itegration code. I will 
look at the OCW's "Classical Mechanics: A Computational Approach" (12.620J / 
6.946J / 8.351J) in the Earth, Atmospheric, and Planetary Sciences section. So, 
yeah, is there anything going on with the SICM style of literate programming a 
math course?

LB

-- 
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] Using the graph library

2016-10-29 Thread Lawrence Bottorff
On Saturday, October 29, 2016 at 3:06:18 PM UTC-4, jhemann wrote:
> Stephen's talk at 4th Racketcon (https://www.youtube.com/watch?v=SvYJF5HC19w) 
> gave me a good tutorial-ish introduction. 
> 
> 
> JBH
> 
> 
> On Sat, Oct 29, 2016 at 8:59 PM, Lawrence Bottorff <bor...@gmail.com> wrote:
> I see the Racket Generic Graph Library, but I don't know how to use it. Where 
> would one go to learn, tutorial-style" the ins and outs of using this 
> library? I take it this library allows you to "roll your own" graph database? 
> I did notice the HTDP has a section on graph things. Would this help?
> 
> 
> 
> LB
> 
> 
> 
> --
> 
> 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.
> 
> 
> 
> 
> 
> -- 
> 
> 
> JBH

I would need something lots more basic-beginner than this talk. The Chang talk 
seems to assume a lot of graph knowledge. I'll pick through the Racket doc on 
the graph library, but it would be better for me to see something that starts 
at the very beginning.

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


[racket-users] Using the graph library

2016-10-29 Thread Lawrence Bottorff
I see the Racket Generic Graph Library, but I don't know how to use it. Where 
would one go to learn, tutorial-style" the ins and outs of using this library? 
I take it this library allows you to "roll your own" graph database? I did 
notice the HTDP has a section on graph things. Would this help?

LB

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


[racket-users] Vector or array type for math vector?

2016-09-15 Thread Lawrence Bottorff
I'm trying out some of the math capabilities of Racket and I'm guessing the 
linear algebra concept of a vector is actually an Array type in Racket, not a 
Vector. Is this correct? Racket's Vector is a data (as with Java's Vector) 
structure, right?

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


[racket-users] Racket module creation in org-mode?

2016-09-06 Thread Lawrence Bottorff
Just wondering if creating a module always has to be based on a .rkt file? 
Would there be any way to create, say, modules (one or more) in an org-mode 
file, perhaps one module per babel code block? . . . Trying to get org-mode to 
be more "modular."

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


[racket-users] racket in geiser (in Emacs): switch language in live REPL to plai-typed?

2016-08-06 Thread Lawrence Bottorff
So, I can start a racket REPL in Emacs geiser. Then I can type

(require typed/racket)

and it seems to take, i.e., I'm ready to go with basic typed racket. This works 
as well from org-mode "babel" code blocks. Now I'd like to do the same with 
plai-typed -- so I can follow along with the PLAI book. How can I switch to the 
plai-typed language in a running geiser racket REPL? Even better would be how 
to do this in an org-mode babel source code block. BTW, I'd use DrRacket (and 
Scribble?) if someone could show/tell me how to do all the things org-mode does 
toward literate programming and leverage all the publishing capabilities (html, 
latex). Also, I don't really need org-mode "to-do".

LB

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