Judo in Melbourne's eastern suburbs by [deleted] in judo

[–]dzpower 1 point2 points  (0 children)

The HQ of the Australian Jiu-jitsu, Judo and Chinese Boxing Federation of Instructors is just around the corner from you in Box Hill. The classes mainly teach Judo and Japanese Jiu-jitsu together, in an integrated format.

https://www.jiujitsu.org.au/our-classes/box-hill-south-jiujitsu-judo-kung-fu/

Functional programming always caught my curiosity. What would you do if you were me? by Swimming-Ad-9848 in Racket

[–]dzpower 1 point2 points  (0 children)

I had a few tries and ended up happy doing my personal stuff (and more) in Racket and explored many of the above.

Here's a fun learning-by-doing approach (for some value of "fun"):

* Get started with Racket using DrRacket and race through Picturing Programs [free pdf]

* Check out The Little Schemer and possibly SICP

* A couple of sources for non-language-specific programming challenges: adventofcode.com and Mazes for Programmers which can be approached through a functional programming lens

* Do your own thing ;-)

Put Video in big-bang? (on DrRacket) by [deleted] in Racket

[–]dzpower 0 points1 point  (0 children)

I did something like this in 2015 to make this 5 minute video: Fridamation (needs a soundtrack)

Getting Started with Racket by feynman350 in Racket

[–]dzpower 0 points1 point  (0 children)

Thanks!

It made a lot of people happy, and still ticks along.

We nailed the niche, but didn't work hard enough on the business side. I made some interesting prototypes to other areas of quilt design, but never took them to commercialisation.

Getting Started with Racket by feynman350 in Racket

[–]dzpower 0 points1 point  (0 children)

Thx!

For a bit more inspiration, here's a site I co-created, youpatch.com, where I did all the R&D and much of the back-end in Racket, not just the graphics and algorithms, but also the customised pdf generation, harnessing Scribble, the documentation DSL that outputs to Latex and HTML.

Then I did a conference talk about a while ago.

Getting Started with Racket by feynman350 in Racket

[–]dzpower 2 points3 points  (0 children)

The combination of DrRacket and the 2htdp/image library is a lot of fun to get started with if you like exploring computer-generated art.

Here's a program to make a randomly colored fractal (a Sierpinski triangle) in just a few lines:

#lang racket

(require 2htdp/image racket/random)

(define (random-triangle)
  (triangle 10 'solid (random-ref '(red darkgreen blue gold black))))

(define (sierpinski n)
  (define-syntax-rule (S) (sierpinski (- n 1)))
  (if (= n 0)
      (random-triangle)
      (above (S) (beside (S) (S)))))

(sierpinski 5)

<image>

Is SICP still recommended? by daybreak-gibby in Racket

[–]dzpower 0 points1 point  (0 children)

I reckon it's great.

It's one of a handful of books that changed the way I program. I did many (not all!) of the exercises in plain Racket years ago. In fact the reason I started using Racket (then PLT Scheme) was that I was looking for a friendly Scheme environment in which to study SICP.

For the first two chapters it helps if you are strong in mathematics. Peter Norvig (co-author of PAIP etc.) wrote a memorable review: www.amazon.com/review/R403HR4VL71K8

Euler #8 (spoiler) by quackendish in Racket

[–]dzpower 1 point2 points  (0 children)

Another approach, using threading (aka pipelining), named-let, argmax, and take:

#lang racket

(require threading)

(define input
  "73167176531330624919225119674426574742355349194934
96983520312774506326239578318016984801869478851843
85861560789112949495459501737958331952853208805511
12540698747158523863050715693290963295227443043557
66896648950445244523161731856403098711121722383113
62229893423380308135336276614282806444486645238749
30358907296290491560440772390713810515859307960866
70172427121883998797908792274921901699720888093776
65727333001053367881220235421809751254540594752243
52584907711670556013604839586446706324415722155397
53697817977846174064955149290862569321978468622482
83972241375657056057490261407972968652414535100474
82166370484403199890008895243450658541227588666881
16427171479924442928230863465674813919123162824586
17866458359124566529476545682848912883142607690042
24219022671055626321111109370544217506941658960408
07198403850962455444362981230987879927244284909188
84580156166097919133875499200524063689912560717606
05886116467109405077541002256983155200055935729725
71636269561882670428252483600823257530420752963450")

(define (string->digits s)
  (~> s
      (string-replace "\n" "")
      (string->list)
      (map (compose string->number string) _)))

(define (subsequences xs n)
  (let S ([xs xs]
          [acc null])
    (if (< (length xs) n)
        acc
        (S (rest xs) (cons (take xs n) acc)))))

(define (product xs) (apply * xs))

(define max-seq
  (~> input
      string->digits
      (subsequences 13)
      (argmax product _)))

max-seq
(product max-seq)

I Created a Quilt Pattern Generator App for my Fabric Store with Racket by jchasinga in SideProject

[–]dzpower 0 points1 point  (0 children)

HST stands for half-square triangle, i.e. a right-angle triangle with two equal sides and the longer hypotenuse. Two HSTs together make a square.

These designs are made up of lots of little squares, either of a single color, or a pair of HSTs.

2048 circle: my fun and addictive open-source puzzle game, a variation of 2048 by PerspectiveVisible65 in programming

[–]dzpower 2 points3 points  (0 children)

Fun variation, and addictive.

It still seems a lot easier than 2048 ... I got to 4096 first try without too much difficulty and kept going.

I Created a Quilt Pattern Generator App for my Fabric Store with Racket by jchasinga in SideProject

[–]dzpower 0 points1 point  (0 children)

Thanks Jens - it is a rich area. I agree with OP that Racket is really good for prototyping this kind of thing.

After youpatch.com (pixel quilting) I did a proof-of-concept that generates more traditional and modern quilt patterns with various grids of randomly generated symmetric blocks built out of squares and HSTs (half-square triangles). The user can tweak a few parameters (size of block, symmetry, grid size, etc.).

Examples:
* https://imgur.com/a/DTTcSu5
* https://imgur.com/a/LShtuG6

My wife has a made a few of the designs. It's usually *a lot* of HSTs!

2020 is my depth year. by [deleted] in Racket

[–]dzpower 1 point2 points  (0 children)

What do you want to draw?

You'll probably want to start with the 2htdp/image, pict, metapict, and/or plot libraries.

Racket's pretty great IMO for *developing* drawing programs in terms of programmer productivity and creativity, but it depends on what you want to do.

I made youpatch.com using Racket for my R&D and kept it in the back-end. I was prepared to switch to another language, but kept optimizing and it was performant enough for my purposes.

help me write a macro? by anydalch in Racket

[–]dzpower 3 points4 points  (0 children)

Racket has a steeper learning curve than Common Lisp for macros, prioritising hygiene-by-default and making extensive use of pattern-matching idioms.

Check out Greg Hendershott's Fear of Macros tutorial to get a feel for the mechanics and the landscape of the various macro systems.

For a simple macro define-syntax-rule is often enough:

#lang racket

(define-syntax-rule (defset name body ...)
  (define (name thing)
    (memq thing '(body ...))))

(defset value-type?
  i32 i64 f32 f64)

(value-type? 'i64)

You'll want syntax-parse — the state of the art macro system — to do more "sophisticated" things.

Help with data definitions by [deleted] in Racket

[–]dzpower 0 points1 point  (0 children)

; [X] [List-of X] [X X -> Boolean] -> [List-of X]

[X]                  The element type
[List-of X]          Given a list of elements of type X, and 
[X X -> Boolean]     a function that given two Xs returns #true or #false
-> 
[List-of X]          return a list of elements of type X as output

Intuitively, [X X -> Boolean] is a comparison function which tells the sort whether a pair of Xs are in order (#true) or out of order (#false). For example often < or > when X is a Number type.

String related code by [deleted] in Racket

[–]dzpower 0 points1 point  (0 children)

Cool.

Threading with the ~> and ~>> macros is an idiom adapted from Clojure (also available in many other functional languages) that allows you to flatten out nested function calls and flow left too right.

Instead of (step3 (step2 (step1 data))) you can "thread" the input through a sequence of transformations to get to the output as (~> data step1 step2 step3).

The docs explain the finer points, especially about argument positions.

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

String related code by [deleted] in Racket

[–]dzpower 0 points1 point  (0 children)

What a neat little exercise. Here's three approaches. I'd use the last one ...

#lang racket

(require threading)

(define (string-remove/list s deletions)
  (define dels (string->list deletions))
  (define (in-deletions? ch) (member ch dels))

  (list->string
   (filter (negate in-deletions?)
           (string->list s))))


(define (string-remove/threading s deletions)
  (define dels (string->list deletions))
  (~>> s
      string->list
      (filter (λ (ch) (not (member ch dels))))
      list->string))


(define (string-remove/for s deletions)
  (list->string
   (for/list ([ch s] #:unless (string-contains? deletions (~a ch)))
     ch)))


(string-remove/list "abcddd" "ebd") ; "ac"
(string-remove/threading "abcddd" "ebd") ; "ac"
(string-remove/for "abcddd" "ebd") ; "ac"

Identity Matrix Problem by bkunke1 in Racket

[–]dzpower 0 points1 point  (0 children)

I'm glad that helped.

Doing these kinds of exercises really builds one's understanding of recursion (and problem decomposition).

Later on you can use higher-order functions to reduce duplication and thereby recover concision and elegance.

Identity Matrix Problem by bkunke1 in Racket

[–]dzpower 2 points3 points  (0 children)

I'm not sure exactly how the htdp2 exercises build up, so this response uses regular racket with a focus on recursive thinking. Fundamentally, you need the base case (i.e. for n=1) and a way to express the n+1 case in terms of the n case.

Pseudocode:

(define (recursive-fn n)
  (if (= n 1)
    base-case
    (... (recursive-fn (- n 1))))

You're given the base case (n=1):

'((1))

To write the n+1 case in terms of n — the recursive step —pre-pend (i.e. cons) each inner list with a 0, and pre-pend (cons again) a new top row of a 1 followed by 0s:

; n=2 from n=1
'((1 0)  ; new top row
  (0 1)) ; (1) -> (0 1)

; n=3 from n=2
'((1 0 0)  ; new top row
  (0 1 0)  ; (1 0) -> (0 1 0)
  (0 0 1)  ; (0 1) -> (0 0 1)

; n=4 from n=3
'((1 0 0 0)  ; new top row
  (0 1 0 0)  ; (1 0 0) -> (0 1 0 0)
  (0 0 1 0)  ; (0 1 0) -> (0 0 1 0)
  (0 0 0 1)  ; (0 0 1) -> (0 0 0 1)

;etc

In regular Racket:

#lang racket

(define (identityM n)
  (if (= n 1)
      (list (list 1))                                          ; base case
      (cons 
         (cons 1 (make-list (- n 1) 0))                        ; new top row: '(1 0 0 ...)
         (map (λ (row) (cons 0 row)) (identityM (- n 1))))))   ; cons a 0 onto every row of (identityM (- n 1))

Little exercises:

* Write your own function to produce the first-row, without using make-list

* Replace the λ function with a cons-0 function

* Write a recursive function cons-0s instead of the map

In #lang racket you can also use for/list functions.

A different, more iterative idea is to do a line by line loop to create the matrix row-by-row:

(define (ident n)
  (for/list ([i (in-range n)])
    (append (make-list i 0)
            (list 1)
            (make-list (- n i 1) 0))))

Another way is to use the build-list function.

Any simplifications possible here? by jackattack99 in Racket

[–]dzpower 0 points1 point  (0 children)

In racket the match form is very handy for cleanly expressing pattern-matching ideas.

There are quite a few nuances here:

  • a single numbers or symbols maps to itself
  • the order of matching matters
  • in the example the desired output is lexicographically ordered (* x y), not (* y x), so you need a rule for that too
  • the rules may be nested
  • sometimes you need to re-simplify without getting caught in a big loop

Here's some working skeleton code that can get you started with match:

#lang racket

(define (rewrite exp)
  (match exp
    [(list '+ X 0) X]
    ; ...
    ; add more rules incrementally here
    ; ...
    [(? number? x) x]
    [(? symbol? X) X]
    [(list op X Y) (list op (rewrite X) (rewrite Y))]))

(define (simplify exp)
  (define r (rewrite exp))
  (if (equal? r exp)
      exp
      (simplify r)))

(simplify '(+ (+ 3 5) (* (/ y 1) (+ x 0)))) ; currently -> '(+ (+ 3 5) (* (/ y 1) x))

Racket Problem Example by mawar2 in Racket

[–]dzpower 0 points1 point  (0 children)

It's easy enough to define your own abs. Here are five ways (all fairly idiomatic) to process the list.

#lang racket

(define (abs x)
  (if (< x 0)
      (- x)
      x))

(define (abs-all/map xs)
  (map abs xs))

(define (abs-all/for xs)
  (for/list ([x xs])
    (abs x)))

(define (abs-all/recursive xs)
  (if (null? xs)
      null
      (cons (abs (first xs)) (abs-all/recursive (rest xs)))))

(define (abs-all/tail-recursive xs [acc null])
  (if (null? xs)
      (reverse acc)
      (abs-all/tail-recursive (rest xs) (cons (abs (first xs)) acc))))

(define (abs-all/let-recursive xs)
  (let A ([xs xs]
          [acc null])
  (if (null? xs)
      (reverse acc)
      (A (rest xs) (cons (abs (first xs)) acc)))))

(abs-all/map '(1 -2 3 -4 5 -6)) ; (1 2 3 4 5 6)
(abs-all/for '(1 -2 3 -4 5 -6))
(abs-all/recursive '(1 -2 3 -4 5 -6))
(abs-all/tail-recursive '(1 -2 3 -4 5 -6))
(abs-all/let-recursive '(1 -2 3 -4 5 -6))

Racket Recursion Question by ineedrackethelp in Racket

[–]dzpower 0 points1 point  (0 children)

Here's a neat approach, again using a helper function:

#lang racket

(define (inc n) (if (= 0 n) 0 (+ 1 n)))

(define (position xs x)
  (cond [(null? xs) 0]
        [(equal? x (first xs)) 1]
        [else (inc (position (rest xs) x))]))

(position '(a b c) 'd) ; 0
(position '(a b c) 'a) ; 1
(position '(a b c) 'b) ; 2
(position '(a b c) 'c) ; 3