Hough transform/Racket: Difference between revisions

m
Fixed syntax highlighting.
(=={{header|Racket}}== implementation added)
 
m (Fixed syntax highlighting.)
 
(2 intermediate revisions by one other user not shown)
Line 1:
<span style='font-family: "Linux Libertine",Georgia,Times,serif;font-size:150%;'>[[Racket]]</span><hr>
{{header|Racket}}
{{trans|C}}
 
Line 19:
===Hough-transform-basic.rkt===
 
<langsyntaxhighlight lang="racket">#lang racket
;;; Note that types are not mentioned here at all in this package
 
Line 80:
[(exn? (λ (x) (place-channel-put ch (cons name (exn-message x)))))]
(sub-hough-transform-channel w h trg-pxls trg-h deg-start deg-end chnl-pxls)
(place-channel-put ch (cons name #t))))</langsyntaxhighlight>
 
===Hough-transform-fast.rkt===
Line 86:
Note the block:
 
<langsyntaxhighlight lang="racket">(require racket/require)
(require (filtered-in
(λ (name) (regexp-replace #rx"unsafe-" name ""))
racket/unsafe/ops))
#;(require racket/flonum racket/fixnum)</langsyntaxhighlight>
 
This uses unsafe, but fast, versions of <code>fx...</code> and <code>fl...</code> functions. If (especially during development and testing), one of these functions receives a non-{fix,flo}num value, then you could lose your interpreter... even DrRacket won't save you. 'Unsafe' means 'unsafe'! So until you are confident use:
 
<langsyntaxhighlight lang="racket">(require racket/require)
#;(require (filtered-in
(λ (name) (regexp-replace #rx"unsafe-" name ""))
racket/unsafe/ops))
(require racket/flonum racket/fixnum)</langsyntaxhighlight>
 
Racket type checks and raises exceptions against <code>fx...</code> and <code>fl...</code> functions. Once these are purged, you can remove your safety harness!
 
<langsyntaxhighlight lang="racket">#lang racket
 
;;; This module tries to be a little smarter about types. It *should* prove to be better performing
Line 200:
[(exn? (λ (x) (place-channel-put ch (cons name (exn-message x)))))]
(sub-hough-transform-channel w h trg-pxls trg-h deg-start deg-end chnl-pxls)
(place-channel-put ch (cons name #t))))</langsyntaxhighlight>
 
===Hough-transform.rkt===
Line 213:
(define (sub-hough-transform-channel w h trg-pxls trg-h deg-start deg-end chnl-pxls) ...)
 
<langsyntaxhighlight lang="racket">#lang racket
;;; Derived from a port of TCL (hence the colouring of the output)
 
Line 329:
(transform-image "180px-Pentagon.png" "Hough-transform-basic.rkt")
(transform-image "180px-Pentagon.png" "Hough-transform-fast.rkt")
)</langsyntaxhighlight>
9,476

edits