Emacs + Geiser on Windows - Hangs when running Chicken Scheme in the REPL - windows

After one or two rounds of expressions loaded from the buffer into the REPL with C-c C-b or C-c M-b, Emacs hangs until I press C-g. Sometimes it ends up switching to the REPL, but even when it does the last sexp never gets evaluated.
I can't find a way to debug or find where it's hanging.
This happens on a fresh install with only a few packages. Here is init.el:
;;-------------------------
;; MELPA
;;-------------------------
(require 'package)
(let* ((no-ssl (and (memq system-type '(windows-nt ms-dos))
(not (gnutls-available-p))))
(proto (if no-ssl "http" "https")))
;; Comment/uncomment these two lines to enable/disable MELPA and MELPA Stable as desired
(add-to-list 'package-archives (cons "melpa" (concat proto "://melpa.org/packages/")) t)
;;(add-to-list 'package-archives (cons "melpa-stable" (concat proto "://stable.melpa.org/packages/")) t)
(when (< emacs-major-version 24)
;; For important compatibility libraries like cl-lib
(add-to-list 'package-archives '("gnu" . (concat proto "://elpa.gnu.org/packages/")))))
(package-initialize)
;; LIST PACKAGES
(setq package-list '(helm
;scheme-complete ;;suspect it messes with chicken & geiser
;chicken-scheme ;;suspect it messes with chicken & geiser
paredit
geiser
slime
restart-emacs
use-package
flycheck
;; sublimity
solarized-theme
zenburn-theme))
; list the repositories containing them
(setq package-archives '(("elpa" . "http://tromey.com/elpa/")
("gnu" . "http://elpa.gnu.org/packages/")
("marmalade" . "http://marmalade-repo.org/packages/")
("melpa" . "http://melpa.org/packages/")))
; activate all the packages (in particular autoloads)
(package-initialize)
; fetch the list of packages available
(unless package-archive-contents
(package-refresh-contents))
; install the missing packages
(dolist (package package-list)
(unless (package-installed-p package)
(package-install package)))
;;-------------------------
;; THA LOOKS
;;-------------------------
(load-theme 'zenburn t)
(set-face-attribute 'default t :font "hack")
(set-frame-font "hack" nil t)
;; other fonts "IBM Plex Mono"
(tool-bar-mode -1)
(scroll-bar-mode -1)
;(desktop-save-mode 1) ;;isn't working right with buffers and geiser
;;-------------------------
;; USE PACKAGE
;;-------------------------
(use-package flycheck
:ensure t
:init (global-flycheck-mode))
;;-------------------------
;; HELM
;;-------------------------
(global-set-key (kbd "M-x") 'helm-M-x) ;; bind to M-x
(helm-mode 1) ;; common Emacs command completion
;;-------------------------
;; flycheck
;;-------------------------
(add-hook 'after-init-hook #'global-flycheck-mode)
;;-------------------------
;; SLIME
;;-------------------------
;; Set your lisp system and, optionally, some contribs
;;(setq inferior-lisp-program "/opt/sbcl/bin/sbcl") ;scbl isn't installed
(setq slime-contribs '(slime-fancy))
(require 'slime)
(slime-setup '(slime-fancy slime-banner))
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(package-selected-packages
(quote
(zenburn-theme solarized-theme flycheck use-package restart-emacs slime geiser paredit helm))))
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
)
Here is last buffer (in scheme-mode with chicken selected):
(define (test x) (+ x x))
(define (test2 y x) (* x y x y x y))
Here is the REPL:
CHICKEN
(c) 2008-2017, The CHICKEN Team
(c) 2000-2007, Felix L. Winkelmann
Version 4.13.0 (rev 68eeaaef)
windows-mingw32-x86-64 [ 64bit manyargs dload ptables ]
compiled 2017-12-11 on yves.more-magic.net (Linux)
; loading C:\chicken/lib/chicken/8/chicken-doc.import.so ...
; loading C:\chicken/lib/chicken/8/chicken.import.so ...
; loading C:\chicken/lib/chicken/8/matchable.import.so ...
; loading C:\chicken/lib/chicken/8/lolevel.import.so ...
; loading C:\chicken/lib/chicken/8/regex.import.so ...
; loading C:\chicken/lib/chicken/8/irregex.import.so ...
; loading C:\chicken/lib/chicken/8/srfi-13.import.so ...
; loading C:\chicken/lib/chicken/8/posix.import.so ...
; loading C:\chicken/lib/chicken/8/data-structures.import.so ...
; loading C:\chicken/lib/chicken/8/srfi-69.import.so ...
; loading C:\chicken/lib/chicken/8/extras.import.so ...
; loading C:\chicken/lib/chicken/8/files.import.so ...
; loading C:\chicken/lib/chicken/8/utils.import.so ...
; loading C:\chicken/lib/chicken/8/srfi-1.import.so ...
; loading C:\chicken/lib/chicken/8/csi.import.so ...
; loading C:\chicken/lib/chicken/8/chicken-doc-text.import.so ...
; loading C:\chicken/lib/chicken/8/fmt.import.so ...
; loading C:\chicken/lib/chicken/8/ports.import.so ...
; loading C:\chicken/lib/chicken/8/foreign.import.so ...
; loading C:\chicken/lib/chicken/8/fmt-unicode.import.so ...
; loading C:\chicken/lib/chicken/8/srfi-4.import.so ...
; loading C:\chicken/lib/chicken/8/utf8-lolevel.import.so ...
; loading C:\chicken/lib/chicken/8/sxml-transforms.import.so ...
; loading C:\chicken/lib/chicken/8/chicken-doc.so ...
; loading C:\chicken/lib/chicken/8/fmt.so ...
; loading C:\chicken/lib/chicken/8/fmt-unicode.so ...
; loading C:\chicken/lib/chicken/8/utf8-lolevel.so ...
; loading C:\chicken/lib/chicken/8/sxml-transforms.so ...
; loading C:\chicken/lib/chicken/8/matchable.so ...
; loading C:\chicken/lib/chicken/8/regex.so ...
; loading C:\chicken/lib/chicken/8/apropos.import.so ...
; loading C:\chicken/lib/chicken/8/memoized-string.import.so ...
; loading C:\chicken/lib/chicken/8/unicode-utils.import.so ...
; loading C:\chicken/lib/chicken/8/type-checks.import.so ...
; loading C:\chicken/lib/chicken/8/type-errors.import.so ...
; loading C:\chicken/lib/chicken/8/symbol-utils.import.so ...
; loading C:\chicken/lib/chicken/8/miscmacros.import.so ...
; loading C:\chicken/lib/chicken/8/apropos.so ...
; loading C:\chicken/lib/chicken/8/memoized-string.so ...
; loading C:\chicken/lib/chicken/8/unicode-utils.so ...
; loading C:\chicken/lib/chicken/8/type-checks.so ...
; loading C:\chicken/lib/chicken/8/type-errors.so ...
; loading C:\chicken/lib/chicken/8/symbol-utils.so ...
; loading library posix ...
; loading C:\chicken/lib/chicken/8/srfi-18.import.so ...
; loading library srfi-18 ...
; loading C:\chicken/lib/chicken/8/tcp.import.so ...
; loading library tcp ...
#;14> (test 234235)
((result "((file-test-lock (\"args\" ((\"required\") (\"optional\" _ ...) (\"key\"))) (\"module\")) (test (\"args\" ((\"required\" x) (\"optional\") (\"key\"))) (\"module\")))") (output . ""))
#;18> 468470
#;19> (test2 9 9)
Error: unbound variable: test2
Call history:
<syntax> (test2 9 9)
<eval> (test2 9 9) <--
#;19>
Here is another example, I ran toggle-debug-on-quit and then hit C-g while it was hanging. I can't make much of the backtrace though. Here it is the buffer and backtrace:
Also, just for kicks I tried running Emacs as an administrator - that made no difference.
buffer:
(define (dog x) (+ x x))
(define (rog y x) (- x y))
(define (cat x y z) (* x y z))
backtrace:
Debugger entered--Lisp error: (quit)
accept-process-output(#<process Chicken REPL> 3.0)
geiser-con--send-string/wait((t (:filter . comint-output-filter) (:tq (("(geiser-eval '#f '(geiser-autodoc '(5235 cat)))\n" "\\(\n#[^;]*;[^:0-9]*:?[0-9]+> \\)" ((:id . 44) (:string . "(geiser-eval '#f '(geiser-autodoc '(5235 cat)))") (:continuation . geiser-autodoc--show-signatures) (:buffer . #<buffer * Chicken REPL *>) (:connection t (:filter . comint-output-filter) #1 (:tq-filter lambda (p s) (geiser-con--tq-filter ... s)) (:eot . "\\(\n#[^;]*;[^:0-9]*:?[0-9]+> \\)") (:prompt . "#[^;]*;[^:0-9]*:?[0-9]+> ") (:debug-prompt) (:is-debugging) (:count . 58) (:completed . #s(hash-table size 65 test eql weakness value rehash-size 1.5 rehash-threshold 0.8 data ( ...))))) . geiser-con--process-completed-request) ("(geiser-eval '#f '(geiser-autodoc '(define)))\n" "\\(\n#[^;]*;[^:0-9]*:?[0-9]+> \\)" ((:id . 45) (:string . "(geiser-eval '#f '(geiser-autodoc '(define)))") (:continuation . geiser-autodoc--show-signatures) (:buffer . #<buffer ck>) (:connection t (:filter . comint-output-filter) #1 (:tq-filter lambda (p s) (geiser-con--tq-filter ... s)) (:eot . "\\(\n#[^;]*;[^:0-9]*:?[0-9]+> \\)") (:prompt . "#[^;]*;[^:0-9]*:?[0-9]+> ") (:debug-prompt) (:is-debugging) (:count . 58) (:completed . #s(hash-table size 65 test eql weakness value rehash-size 1.5 rehash-threshold 0.8 data ( ...))))) . geiser-con--process-completed-request) ("(geiser-eval '#f '(geiser-autodoc '(define)))\n" "\\(\n#[^;]*;[^:0-9]*:?[0-9]+> \\)" ((:id . 46) (:string . "(geiser-eval '#f '(geiser-autodoc '(define)))") (:continuation . geiser-autodoc--show-signatures) (:buffer . #<buffer ck>) (:connection t (:filter . comint-output-filter) #1 (:tq-filter lambda (p s) (geiser-con--tq-filter ... s)) (:eot . "\\(\n#[^;]*;[^:0-9]*:?[0-9]+> \\)") (:prompt . "#[^;]*;[^:0-9]*:?[0-9]+> ") (:debug-prompt) (:is-debugging) (:count . 58) (:completed . #s(hash-table size 65 test eql weakness value rehash-size 1.5 rehash-threshold 0.8 data ( ...))))) . geiser-con--process-completed-request) ("(geiser-eval '#f '(geiser-autodoc '(ta ta define)))\n" "\\(\n#[^;]*;[^:0-9]*:?[0-9]+> \\)" ((:id . 47) (:string . "(geiser-eval '#f '(geiser-autodoc '(ta ta define)))") (:continuation . geiser-autodoc--show-signatures) (:buffer . #<buffer ck>) (:connection t (:filter . comint-output-filter) #1 (:tq-filter lambda (p s) (geiser-con--tq-filter ... s)) (:eot . "\\(\n#[^;]*;[^:0-9]*:?[0-9]+> \\)") (:prompt . "#[^;]*;[^:0-9]*:?[0-9]+> ") (:debug-prompt) (:is-debugging) (:count . 58) (:completed . #s(hash-table size 65 test eql weakness value rehash-size 1.5 rehash-threshold 0.8 data ( ...))))) . geiser-con--process-completed-request) ("(geiser-eval '#f '(geiser-autodoc '(tac tac define)))\n" "\\(\n#[^;]*;[^:0-9]*:?[0-9]+> \\)" ((:id . 48) (:string . "(geiser-eval '#f '(geiser-autodoc '(tac tac define)))") (:continuation . geiser-autodoc--show-signatures) (:buffer . #<buffer ck>) (:connection t (:filter . comint-output-filter) #1 (:tq-filter lambda (p s) (geiser-con--tq-filter ... s)) (:eot . "\\(\n#[^;]*;[^:0-9]*:?[0-9]+> \\)") (:prompt . "#[^;]*;[^:0-9]*:?[0-9]+> ") (:debug-prompt) (:is-debugging) (:count . 58) (:completed . #s(hash-table size 65 test eql weakness value rehash-size 1.5 rehash-threshold 0.8 data ( ...))))) . geiser-con--process-completed-request) ("(geiser-eval '#f '(geiser-autodoc '(tac define)))\n" "\\(\n#[^;]*;[^:0-9]*:?[0-9]+> \\)" ((:id . 49) (:string . "(geiser-eval '#f '(geiser-autodoc '(tac define)))") (:continuation . geiser-autodoc--show-signatures) (:buffer . #<buffer ck>) (:connection t (:filter . comint-output-filter) #1 (:tq-filter lambda (p s) (geiser-con--tq-filter ... s)) (:eot . "\\(\n#[^;]*;[^:0-9]*:?[0-9]+> \\)") (:prompt . "#[^;]*;[^:0-9]*:?[0-9]+> ") (:debug-prompt) (:is-debugging) (:count . 58) (:completed . #s(hash-table size 65 test eql weakness value rehash-size 1.5 rehash-threshold 0.8 data ( ...))))) . geiser-con--process-completed-request) ("(geiser-eval '#f '(geiser-autodoc '(z tac define)))\n" "\\(\n#[^;]*;[^:0-9]*:?[0-9]+> \\)" ((:id . 50) (:string . "(geiser-eval '#f '(geiser-autodoc '(z tac define)))") (:continuation . geiser-autodoc--show-signatures) (:buffer . #<buffer ck>) (:connection t (:filter . comint-output-filter) #1 (:tq-filter lambda (p s) (geiser-con--tq-filter ... s)) (:eot . "\\(\n#[^;]*;[^:0-9]*:?[0-9]+> \\)") (:prompt . "#[^;]*;[^:0-9]*:?[0-9]+> ") (:debug-prompt) (:is-debugging) (:count . 58) (:completed . #s(hash-table size 65 test eql weakness value rehash-size 1.5 rehash-threshold 0.8 data ( ...))))) . geiser-con--process-completed-request) ("(geiser-eval '#f '(geiser-autodoc '(define)))\n" "\\(\n#[^;]*;[^:0-9]*:?[0-9]+> \\)" ((:id . 51) (:string . "(geiser-eval '#f '(geiser-autodoc '(define)))") (:continuation . geiser-autodoc--show-signatures) (:buffer . #<buffer ck>) (:connection t (:filter . comint-output-filter) #1 (:tq-filter lambda (p s) (geiser-con--tq-filter ... s)) (:eot . "\\(\n#[^;]*;[^:0-9]*:?[0-9]+> \\)") (:prompt . "#[^;]*;[^:0-9]*:?[0-9]+> ") (:debug-prompt) (:is-debugging) (:count . 58) (:completed . #s(hash-table size 65 test eql weakness value rehash-size 1.5 rehash-threshold 0.8 data ( ...))))) . geiser-con--process-completed-request) ("(geiser-eval '#f '(geiser-autodoc '(/ / define)))\n" "\\(\n#[^;]*;[^:0-9]*:?[0-9]+> \\)" ((:id . 52) (:string . "(geiser-eval '#f '(geiser-autodoc '(/ / define)))") (:continuation . geiser-autodoc--show-signatures) (:buffer . #<buffer ck>) (:connection t (:filter . comint-output-filter) #1 (:tq-filter lambda (p s) (geiser-con--tq-filter ... s)) (:eot . "\\(\n#[^;]*;[^:0-9]*:?[0-9]+> \\)") (:prompt . "#[^;]*;[^:0-9]*:?[0-9]+> ") (:debug-prompt) (:is-debugging) (:count . 58) (:completed . #s(hash-table size 65 test eql weakness value rehash-size 1.5 rehash-threshold 0.8 data ( ...))))) . geiser-con--process-completed-request) ("(geiser-eval '#f '(geiser-autodoc '(/ define)))\n" "\\(\n#[^;]*;[^:0-9]*:?[0-9]+> \\)" ((:id . 53) (:string . "(geiser-eval '#f '(geiser-autodoc '(/ define)))") (:continuation . geiser-autodoc--show-signatures) (:buffer . #<buffer ck>) (:connection t (:filter . comint-output-filter) #1 (:tq-filter lambda (p s) (geiser-con--tq-filter ... s)) (:eot . "\\(\n#[^;]*;[^:0-9]*:?[0-9]+> \\)") (:prompt . "#[^;]*;[^:0-9]*:?[0-9]+> ") (:debug-prompt) (:is-debugging) (:count . 58) (:completed . #s(hash-table size 65 test eql weakness value rehash-size 1.5 rehash-threshold 0.8 data ( ...))))) . geiser-con--process-completed-request) ("(geiser-eval '#f '(begin (define (dog x) (+ x x))\n(define (rog y x) (- x y))\n(define (cat x y z) (* x y z))\n(define (tac y z) (/ x y))))\n" "\\(\n#[^;]*;[^:0-9]*:?[0-9]+> \\)" ((:id . 54) (:string . "(geiser-eval '#f '(begin (define (dog x) (+ x x))\n(define (rog y x) (- x y))\n(define (cat x y z) (* x y z))\n(define (tac y z) (/ x y))))") (:continuation) (:buffer . #<buffer ck>) (:connection t (:filter . comint-output-filter) #1 (:tq-filter lambda (p s) (geiser-con--tq-filter ... s)) (:eot . "\\(\n#[^;]*;[^:0-9]*:?[0-9]+> \\)") (:prompt . "#[^;]*;[^:0-9]*:?[0-9]+> ") (:debug-prompt) (:is-debugging) (:count . 58) (:completed . #s(hash-table size 65 test eql weakness value rehash-size 1.5 rehash-threshold 0.8 data ( ...))))) . geiser-con--process-completed-request) ("(geiser-eval '#f '(geiser-autodoc '(tac tac)))\n" "\\(\n#[^;]*;[^:0-9]*:?[0-9]+> \\)" ((:id . 55) (:string . "(geiser-eval '#f '(geiser-autodoc '(tac tac)))") (:continuation . geiser-autodoc--show-signatures) (:buffer . #<buffer * Chicken REPL *>) (:connection t (:filter . comint-output-filter) #1 (:tq-filter lambda (p s) (geiser-con--tq-filter ... s)) (:eot . "\\(\n#[^;]*;[^:0-9]*:?[0-9]+> \\)") (:prompt . "#[^;]*;[^:0-9]*:?[0-9]+> ") (:debug-prompt) (:is-debugging) (:count . 58) (:completed . #s(hash-table size 65 test eql weakness value rehash-size 1.5 rehash-threshold 0.8 data ( ...))))) . geiser-con--process-completed-request) ("(geiser-eval '#f '(geiser-autodoc '(tac)))\n" "\\(\n#[^;]*;[^:0-9]*:?[0-9]+> \\)" ((:id . 56) (:string . "(geiser-eval '#f '(geiser-autodoc '(tac)))") (:continuation . geiser-autodoc--show-signatures) (:buffer . #<buffer * Chicken REPL *>) (:connection t (:filter . comint-output-filter) #1 (:tq-filter lambda (p s) (geiser-con--tq-filter ... s)) (:eot . "\\(\n#[^;]*;[^:0-9]*:?[0-9]+> \\)") (:prompt . "#[^;]*;[^:0-9]*:?[0-9]+> ") (:debug-prompt) (:is-debugging) (:count . 58) (:completed . #s(hash-table size 65 test eql weakness value rehash-size 1.5 rehash-threshold 0.8 data ( ...))))) . geiser-con--process-completed-request) ("(geiser-eval '#f '(geiser-autodoc '(8 tac)))\n" "\\(\n#[^;]*;[^:0-9]*:?[0-9]+> \\)" ((:id . 57) (:string . "(geiser-eval '#f '(geiser-autodoc '(8 tac)))") (:continuation . geiser-autodoc--show-signatures) (:buffer . #<buffer * Chicken REPL *>) (:connection t (:filter . comint-output-filter) #1 (:tq-filter lambda (p s) (geiser-con--tq-filter ... s)) (:eot . "\\(\n#[^;]*;[^:0-9]*:?[0-9]+> \\)") (:prompt . "#[^;]*;[^:0-9]*:?[0-9]+> ") (:debug-prompt) (:is-debugging) (:count . 58) (:completed . #s(hash-table size 65 test eql weakness value rehash-size 1.5 rehash-threshold 0.8 data ( ...))))) . geiser-con--process-completed-request) ("(geiser-eval '#f '(begin (define (dog x) (+ x x))\n(define (rog y x) (- x y))\n(define (cat x y z) (* x y z))\n(define (tac y z) (/ x y))))\n" "\\(\n#[^;]*;[^:0-9]*:?[0-9]+> \\)" ((:id . 58) (:string . "(geiser-eval '#f '(begin (define (dog x) (+ x x))\n(define (rog y x) (- x y))\n(define (cat x y z) (* x y z))\n(define (tac y z) (/ x y))))") (:continuation . geiser-eval--set-sync-retort) (:buffer . #<buffer ck>) (:connection t (:filter . comint-output-filter) #1 (:tq-filter lambda (p s) (geiser-con--tq-filter ... s)) (:eot . "\\(\n#[^;]*;[^:0-9]*:?[0-9]+> \\)") (:prompt . "#[^;]*;[^:0-9]*:?[0-9]+> ") (:debug-prompt) (:is-debugging) (:count . 58) (:completed . #s(hash-table size 65 test eql weakness value rehash-size 1.5 rehash-threshold 0.8 data ( ...))))) . geiser-con--process-completed-request)) #<process Chicken REPL> . #<buffer tq-temp-Chicken REPL>) (:tq-filter lambda (p s) (geiser-con--tq-filter (quote ((("(geiser-eval '#f '(geiser-autodoc '(5235 cat)))\n" "\\(\n#[^;]*;[^:0-9]*:?[0-9]+> \\)" (... ... ... ... ...) . geiser-con--process-completed-request) ("(geiser-eval '#f '(geiser-autodoc '(define)))\n" "\\(\n#[^;]*;[^:0-9]*:?[0-9]+> \\)" (... ... ... ... ...) . geiser-con--process-completed-request) ("(geiser-eval '#f '(geiser-autodoc '(define)))\n" "\\(\n#[^;]*;[^:0-9]*:?[0-9]+> \\)" (... ... ... ... ...) . geiser-con--process-completed-request) ("(geiser-eval '#f '(geiser-autodoc '(ta ta define)))\n" "\\(\n#[^;]*;[^:0-9]*:?[0-9]+> \\)" (... ... ... ... ...) . geiser-con--process-completed-request) ("(geiser-eval '#f '(geiser-autodoc '(tac tac define)))\n" "\\(\n#[^;]*;[^:0-9]*:?[0-9]+> \\)" (... ... ... ... ...) . geiser-con--process-completed-request) ("(geiser-eval '#f '(geiser-autodoc '(tac define)))\n" "\\(\n#[^;]*;[^:0-9]*:?[0-9]+> \\)" (... ... ... ... ...) . geiser-con--process-completed-request) ("(geiser-eval '#f '(geiser-autodoc '(z tac define)))\n" "\\(\n#[^;]*;[^:0-9]*:?[0-9]+> \\)" (... ... ... ... ...) . geiser-con--process-completed-request) ("(geiser-eval '#f '(geiser-autodoc '(define)))\n" "\\(\n#[^;]*;[^:0-9]*:?[0-9]+> \\)" (... ... ... ... ...) . geiser-con--process-completed-request) ("(geiser-eval '#f '(geiser-autodoc '(/ / define)))\n" "\\(\n#[^;]*;[^:0-9]*:?[0-9]+> \\)" (... ... ... ... ...) . geiser-con--process-completed-request) ("(geiser-eval '#f '(geiser-autodoc '(/ define)))\n" "\\(\n#[^;]*;[^:0-9]*:?[0-9]+> \\)" (... ... ... ... ...) . geiser-con--process-completed-request) ("(geiser-eval '#f '(begin (define (dog x) (+ x x))\n(define (rog y x) (- x y))\n(define (cat x y z) (* x y z))\n(define (tac y z) (/ x y))))\n" "\\(\n#[^;]*;[^:0-9]*:?[0-9]+> \\)" (... ... ... ... ...) . geiser-con--process-completed-request) ("(geiser-eval '#f '(geiser-autodoc '(tac tac)))\n" "\\(\n#[^;]*;[^:0-9]*:?[0-9]+> \\)" (... ... ... ... ...) . geiser-con--process-completed-request) ("(geiser-eval '#f '(geiser-autodoc '(tac)))\n" "\\(\n#[^;]*;[^:0-9]*:?[0-9]+> \\)" (... ... ... ... ...) . geiser-con--process-completed-request) ("(geiser-eval '#f '(geiser-autodoc '(8 tac)))\n" "\\(\n#[^;]*;[^:0-9]*:?[0-9]+> \\)" (... ... ... ... ...) . geiser-con--process-completed-request) ("(geiser-eval '#f '(begin (define (dog x) (+ x x))\n(define (rog y x) (- x y))\n(define (cat x y z) (* x y z))\n(define (tac y z) (/ x y))))\n" "\\(\n#[^;]*;[^:0-9]*:?[0-9]+> \\)" (... ... ... ... ...) . geiser-con--process-completed-request)) #<process Chicken REPL> . #<buffer tq-temp-Chicken REPL>)) s)) (:eot . "\\(\n#[^;]*;[^:0-9]*:?[0-9]+> \\)") (:prompt . "#[^;]*;[^:0-9]*:?[0-9]+> ") (:debug-prompt) (:is-debugging) (:count . 58) (:completed . #s(hash-table size 65 test eql weakness value rehash-size 1.5 rehash-threshold 0.8 data ( ...)))) "(geiser-eval '#f '(begin (define (dog x) (+ x x))\n(define (rog y x) (- x y))\n(define (cat x y z) (* x y z))\n(define (tac y z) (/ x y))))" geiser-eval--set-sync-retort nil nil)
geiser-eval--send/wait((:eval (:scm "(begin (define (dog x) (+ x x))\n(define (rog y x) (- x y))\n(define (cat x y z) (* x y z))\n(define (tac y z) (/ x y)))")))
geiser-debug--send-region(nil 1 110 geiser--go-to-repl t nil)
geiser-eval-region(1 110 t nil nil)
geiser-eval-buffer(t)
geiser-eval-buffer-and-go()
funcall-interactively(geiser-eval-buffer-and-go)
call-interactively(geiser-eval-buffer-and-go nil nil)
command-execute(geiser-eval-buffer-and-go)

Related

early exiting a recursive procedure

Watching this video (11:56)
It shows a recursive procedure that multiplies the numbers contained in a list
The idea is that if the list contains a zero, the whole stack of recursive calls can be discarded and 0 can be returned
So to save some multiplications
It does so by early exiting the procedure with delimited continuations
I'd like to reproduce this in Guile Scheme and I wrote this code
(define (times numbers)
(define (times-iter numbers)
(match numbers
((a-number rest ...)
(* a-number (times rest)))
('() 1)
((0 rest ...) (shift k 0) )
))
(reset (times-iter numbers))
)
it multiplies correctly but if I pass it a list containing a zero and I trace such call, I get
scheme#(guile-user)> ,trace (times2 '(1 3 0 4))
trace: | (times2 (1 3 0 4))
trace: | | (default-prompt-tag##ice-9/control)
trace: | | (_)
trace: | | ("prompt")
trace: | | (_)
trace: | | | (list? (3 0 4))
trace: | | | #t
trace: | | | (times (3 0 4))
trace: | | | | (list? (0 4))
trace: | | | | #t
trace: | | | | (times (0 4))
trace: | | | | | (list? (4))
trace: | | | | | #t
trace: | | | | | (times (4))
trace: | | | | | | (list? ())
trace: | | | | | | #t
trace: | | | | | | (times ())
trace: | | | | | | 1
trace: | | | | | 4
trace: | | | | 0
trace: | | | 0
trace: | | 0
trace: | (_ #<procedure values _> (0))
trace: | (_ 0)
trace: | 0
scheme#(guile-user)>
It seems to me that the early exit doesn't kick in and the whole stack of multiplications gets applied
What am I doing wrong ?
Based on the comments, it's unclear if you still have a question here. (shift k 0) does indeed clear the current continuation and discards it.
I don't have Guile on this machine but I wrote a simplified times example below with racket using cond -
(require racket/control)
(define/traced (times numbers)
(cond ((null? numbers) 1)
((zero? (car numbers)) (shift k 0)) ;; <- shift
(else (* (car numbers) (times (cdr numbers))))))
#ignisvolens provides define/traced in this Q&A. reset wraps the expression but you could move it to an inner auxiliary function like you did in your code -
(reset ;; <- reset
(times '(1 2 3 4 5 6 7 8 9)))
(times (1 2 3 4 5 6 7 8 9)) ...
(times (2 3 4 5 6 7 8 9)) ...
(times (3 4 5 6 7 8 9)) ...
(times (4 5 6 7 8 9)) ...
(times (5 6 7 8 9)) ...
(times (6 7 8 9)) ...
(times (7 8 9)) ...
(times (8 9)) ...
(times (9)) ...
(times ()) ...
-> (1)
-> (9)
-> (72)
-> (504)
-> (3024)
-> (15120)
-> (60480)
-> (181440)
-> (362880)
-> (362880)
362880
We can see the immediate exit when the 0 is encountered -
(reset (times '(1 2 0 4 5 6 7 8 9)))
(times (1 2 0 4 5 6 7 8 9)) ...
(times (2 0 4 5 6 7 8 9)) ...
(times (0 4 5 6 7 8 9)) ...
0
Notice in the first example, define/traced shows -> ... when times returns a value. In the second example, the entire continuation is discarded and times never fully evaluates.

UTF-8 bytes to string

I'm trying to convert a list like '(110 111 101 204 136 108) to a string like "noël".
I tried using (mapcar (lambda (c) (decode-char 'unicode c)) '(110 111 101 204 136 108)), but it resulted in (110 111 101 204 136 108), the same as the input. (Also, I recognize that there's no way to decode a Unicode character from a single byte of UTF-8, so that's definitely the wrong function.)
A few options...
(with-temp-buffer
(set-buffer-multibyte nil)
(apply #'insert '(110 111 101 204 136 108))
(decode-coding-region (point-min) (point-max) 'utf-8 t))
or:
(decode-coding-string
(mapconcat #'byte-to-string '(110 111 101 204 136 108) "")
'utf-8)
or more directly:
(string-as-multibyte
(apply #'unibyte-string '(110 111 101 204 136 108)))

CLIPS - looking for match between random slots in multislot fields

Consider such situation. I have such templates:
(deftemplate MAIN::simplecause
(multislot coraxinfo (type INTEGER) (default undefined))
(multislot changeinfo (type SYMBOL) (default undefined)))
(deftemplate MAIN::finalcause
(multislot coraxinfo (type INTEGER) (default undefined))
(multislot changeinfo (type SYMBOL) (default undefined)))
I know that in coraxinfo slot I will always have not more than 14 values (maybe less, but never more). I also now that in changeinfo multislot I will have not more than 13 values.
I am trying to write a rule which will find all possible matches between any facts I will have.
For instance:
(deffacts start
(simplecause (coraxinfo 1 2 3) (changeinfo a b c))
(simplecause (coraxinfo 7 8 2 3 9) (changeinfo d a b e))
(simplecause (coraxinfo 2 3 10 13) (changeinfo f g a b z))
(simplecause (coraxinfo 77 88 99 66) (changeinfo k m l s))
(simplecause (coraxinfo 88 99 11 22) (changeinfo v k m w))
(simplecause (coraxinfo 13 88 99) (changeinfo k m))
(simplecause (coraxinfo 666 777 888) (changeinfo abc def))
(simplecause (coraxinfo 666 111 222 888 333 444 555 777 999) (changeinfo abc 1a 2a 3a def 4a)))
I would need to get this (order of values in each multislot doesn't matter):
(finalcause (coraxinfo 2 3) (changeinfo a b))
(finalcause 88 99) (changeinfo k m))
(finalcause 666 777 888) (changeinfo abc def))
For now I have stopped on this function:
(defrule cause_generalization_initial1
?f1 <- (simplecause (coraxinfo $?coraxmatch1 $?coraxmatch2 $?coraxmatch3 $?coraxmatch4 $?coraxmatch5 $?coraxmatch6 $?coraxmatch7) (changeinfo $?pricematch1 $?pricematch2 $?pricematch3 $?pricematch4 $?pricematch5 $?pricematch6 $?pricematch7))
?f2 <- (simplecause (coraxinfo $?coraxmatch1 $?coraxmatch2 $?coraxmatch3 $?coraxmatch4 $?coraxmatch5 $?coraxmatch6 $?coraxmatch7) (changeinfo $?pricematch1 $?pricematch2 $?pricematch3 $?pricematch4 $?pricematch5 $?pricematch6 $?pricematch7))
(test (neq ?f1 ?f2))
(not (finalcause (coraxinfo $?coraxmatch1 $?coraxmatch2 $?coraxmatch3 $?coraxmatch4 $?coraxmatch5 $?coraxmatch6 $?coraxmatch7) (changeinfo $?pricematch1 $?pricematch2 $?pricematch3 $?pricematch4 $?pricematch5 $?pricematch6 $?pricematch7)))
=>
(assert (finalcause (coraxinfo $?coraxmatch1 $?coraxmatch2 $?coraxmatch3 $?coraxmatch4 $?coraxmatch5 $?coraxmatch6 $?coraxmatch7) (changeinfo $?pricematch1 $?pricematch2 $?pricematch3 $?pricematch4 $?pricematch5 $?pricematch6 $?pricematch7))))
It is a little bit clumsy, but as far as I remember $? means 'zero or more', so even if I will have less fields than I have specified in search patter it should work. I use up to 7 multislots in each of patterns since having 14 or 13 values as a maximum means that in worst case every second value in multislot will match to smth in other fact.
The issue that when I load the facts specified in deffacts CLIPS goes to a kind of infinite loop - it doesn't responds for a long time so I beleive I have made a mistake in my rule. Also this rule should kill the engine in case I will have couple of facts which are almost same with the difference only in one field. In such case it will produce terrible amount of matches between them. Any idea where I was wrong? I will really appreciate any suggestions.
UPDATE. If we are trying to take the approach of constructin (finalcause) facts by adding one value to coraxinfo and changeinfo slots at a time than I have currently stopped on these 2 rules:
Creates initial finalcause fact with one matching value in both multislots:
(defrule cause_generalization_initial
?f1 <- (simplecause (coraxinfo $? ?coraxmatch $?) (changeinfo $? ?changematch $?))
?f2 <- (simplecause (coraxinfo $? ?coraxmatch $?) (changeinfo $? ?changematch $?))
(test (neq ?f1 ?f2))
(not (finalcause (coraxinfo ?coraxmatch) (changeinfo ?changematch)))
=>
(assert (finalcause (coraxinfo ?coraxmatch) (changeinfo ?changematch)))
If we have any finalcause fact we try to check that all the multislot values in it are subset of everything before the ?coraxmatchafter value in both matching simplecause facts and assert an extended finalcause. I beleive this rule should be able to 'jump over the gaps' in matching simplecauses.
(defrule cause_generalization_advanced
?f1 <- (simplecause (coraxinfo $?coraxbefore1 ?coraxmatchafter $?) (changeinfo $?changebefore1 ?changematchafter $?))
?f2 <- (simplecause (coraxinfo $?coraxbefore2 ?coraxmatchafter $?) (changeinfo $?changebefore2 ?changematchafter $?))
(test (neq ?f1 ?f2))
(finalcause (coraxinfo $?finalcoraxbefore) (changeinfo $?finalchangebefore))
(test (and (subsetp $?finalcoraxbefore $?coraxbefore1) (subsetp $?finalcoraxbefore $?coraxbefore2)
(subsetp $?finalchangebefore $?changebefore1) (subsetp $?finalchangebefore $?changebefore2)))
=>
(assert (finalcause (coraxinfo $?finalcoraxbefore ?coraxmatchafter) (changeinfo $?finalchangebefore ?changematchafter))))
I use the rules with these deffacts (notice that deffacts is different from the one above):
(deffacts start
(simplecause (coraxinfo 1 2 3) (changeinfo a b c))
(simplecause (coraxinfo 7 8 2 3 9) (changeinfo d a b e))
(simplecause (coraxinfo 2 3 10 13) (changeinfo f g a b z))
(simplecause (coraxinfo 77 88 99 66) (changeinfo k m l s))
(simplecause (coraxinfo 88 99 11 22) (changeinfo v k m w))
(simplecause (coraxinfo 13 88 99) (changeinfo k m))
(simplecause (coraxinfo 666 777 888) (changeinfo abc def))
(simplecause (coraxinfo 666 111 222 777 333 444 555 888 999) (changeinfo abc 1a 2a 3a def 4a)))
The issue here is that I expected that it will be able to produce the finalcause for 3 matching fields but it produces only finalcause facts with 2 matching fields and I don't get why. Shouldn't it notice that these 3 facts are falling into the second rule?
(simplecause (coraxinfo 666 777 888) (changeinfo abc def))
(simplecause (coraxinfo 666 111 222 777 333 444 555 888 999) (changeinfo abc 1a 2a 3a def 4a))
(finalcause (coraxinfo 666 888) (changeinfo abc def))
Output of both rules is:
f-0 (initial-fact)
f-1 (simplecause (coraxinfo 1 2 3) (changeinfo a b c))
f-2 (simplecause (coraxinfo 7 8 2 3 9) (changeinfo d a b e))
f-3 (simplecause (coraxinfo 2 3 10 13) (changeinfo f g a b z))
f-4 (simplecause (coraxinfo 77 88 99 66) (changeinfo k m l s))
f-5 (simplecause (coraxinfo 88 99 11 22) (changeinfo v k m w))
f-6 (simplecause (coraxinfo 13 88 99) (changeinfo k m))
f-7 (simplecause (coraxinfo 666 777 888) (changeinfo abc def))
f-8 (simplecause (coraxinfo 666 111 222 777 333 444 555 888 999) (changeinfo abc 1a 2a 3a def 4a))
f-9 (finalcause (coraxinfo 666) (changeinfo abc))
f-10 (finalcause (coraxinfo 666 888) (changeinfo abc def))
f-11 (finalcause (coraxinfo 666 777) (changeinfo abc def))
f-12 (finalcause (coraxinfo 666) (changeinfo def))
f-13 (finalcause (coraxinfo 777) (changeinfo abc))
f-14 (finalcause (coraxinfo 777 888) (changeinfo abc def))
f-15 (finalcause (coraxinfo 777) (changeinfo def))
f-16 (finalcause (coraxinfo 888) (changeinfo abc))
f-17 (finalcause (coraxinfo 888) (changeinfo def))
f-18 (finalcause (coraxinfo 88) (changeinfo k))
f-19 (finalcause (coraxinfo 88 99) (changeinfo k m))
f-20 (finalcause (coraxinfo 88) (changeinfo m))
f-21 (finalcause (coraxinfo 99) (changeinfo k))
f-22 (finalcause (coraxinfo 99) (changeinfo m))
f-23 (finalcause (coraxinfo 2) (changeinfo a))
f-24 (finalcause (coraxinfo 2 3) (changeinfo a b))
f-25 (finalcause (coraxinfo 2) (changeinfo b))
f-26 (finalcause (coraxinfo 3) (changeinfo a))
f-27 (finalcause (coraxinfo 3) (changeinfo b))
Using 7 multifield variables, you're creating a combinatoric explosion in the number of ways the pattern can be matched. Look at the number of ways in which just the first pattern in your rule can be matched:
CLIPS>
(deftemplate simplecause
(multislot coraxinfo)
(multislot changeinfo))
CLIPS>
(deftemplate finalcause
(multislot coraxinfo)
(multislot changeinfo))
CLIPS>
(defrule cause_generalization_initial1
(simplecause (coraxinfo $?coraxmatch1 $?coraxmatch2 $?coraxmatch3 $?coraxmatch4 $?coraxmatch5 $?coraxmatch6 $?coraxmatch7)
(changeinfo $?pricematch1 $?pricematch2 $?pricematch3 $?pricematch4 $?pricematch5 $?pricematch6 $?pricematch7))
=>)
CLIPS> (assert (simplecause (coraxinfo) (changeinfo)))
<Fact-1>
CLIPS> (agenda)
0 cause_generalization_initial1: f-1
For a total of 1 activation.
CLIPS> (modify 1 (coraxinfo a) (changeinfo 1))
<Fact-2>
CLIPS> (agenda)
0 cause_generalization_initial1: f-2
.
.
.
0 cause_generalization_initial1: f-2
For a total of 49 activations.
CLIPS> (modify 2 (coraxinfo a b) (changeinfo 1 2))
<Fact-3>
CLIPS> (agenda)
0 cause_generalization_initial1: f-3
.
.
.
0 cause_generalization_initial1: f-3
For a total of 784 activations.
CLIPS> (modify 3 (coraxinfo a b c) (changeinfo 1 2 3))
<Fact-4>
CLIPS> (agenda)
0 cause_generalization_initial1: f-4
.
.
.
0 cause_generalization_initial1: f-4
For a total of 7056 activations.
CLIPS> (modify 4 (coraxinfo a b c d) (changeinfo 1 2 3 4))
<Fact-5>
CLIPS> (agenda)
0 cause_generalization_initial1: f-5
.
.
.
0 cause_generalization_initial1: f-5
For a total of 44100 activations.
CLIPS>
If the coraxinfo and changeinfo slots are empty there's only way the pattern can be matched and only one activation. If each slot contains a single value there's 7 different ways that each slot can be matched (a single value in each of the seven variables with the remaining variables empty). Between the two slots that means there's 49 different ways the pattern can be matched.
Once you get to 4 values in each slot, there's 44100 different ways that single pattern can be matched. That means by adding a second pattern there's 44,100 * 44,100 combinations that need to be compared. That's 1,944,810,000 comparisons that need to be made for the assertion of a single fact and you've got 8 facts including one with 9 values in one slot and 6 in the other.
This is not a problem you're going to solve with a single rule. Probably the best approach is to construct the finalcause facts one element at a time using multiple rules. For example, first determine that there are two facts with 666 in them and create a (finalcause (coraxinfo 666) (changeinfo)) fact. Then have a rule which determines that there are two facts both having all the values present in finalcause plus an additional value that is not present and add that value. For example, (finalcause (coraxinfo 666 777) (changeinfo)). You can then have rules that remove the intermediate results.
You'll also want to construct the rules so that you don't generate permutations. For example, you don't want to generate all of these facts which are different but equivalent:
(finalcause (coraxinfo 666 777 888) (changeinfo abc def))
(finalcause (coraxinfo 666 888 777) (changeinfo abc def))
(finalcause (coraxinfo 777 666 888) (changeinfo abc def))
(finalcause (coraxinfo 777 888 666) (changeinfo abc def))
(finalcause (coraxinfo 888 666 777) (changeinfo abc def))
(finalcause (coraxinfo 888 777 666) (changeinfo abc def))
(finalcause (coraxinfo 666 777 888) (changeinfo def abc))
(finalcause (coraxinfo 666 888 777) (changeinfo def abc))
(finalcause (coraxinfo 777 666 888) (changeinfo def abc))
(finalcause (coraxinfo 777 888 666) (changeinfo def abc))
(finalcause (coraxinfo 888 666 777) (changeinfo def abc))
(finalcause (coraxinfo 888 777 666) (changeinfo def abc))
To do this, I'd suggest sorting the values that you place in finalcause slots so there's a unique ordering for the equivalent facts.
With Gary's help, here is the variant which will do this:
(deftemplate MAIN::simplecause
(multislot coraxinfo (type INTEGER) (default 0))
(multislot changeinfo (type SYMBOL) (default undefined)))
(deftemplate MAIN::finalcause
(multislot coraxinfo (type INTEGER) (default 0))
(multislot changeinfo (type SYMBOL) (default undefined)))
(deffacts start
(simplecause (coraxinfo 1 2 3) (changeinfo a b c))
(simplecause (coraxinfo 7 8 2 3 9) (changeinfo d a b e))
(simplecause (coraxinfo 2 3 10 13) (changeinfo f g a b z))
(simplecause (coraxinfo 77 88 99 66) (changeinfo k m l s))
(simplecause (coraxinfo 88 99 11 22) (changeinfo v k m w))
(simplecause (coraxinfo 13 88 99) (changeinfo k m))
(simplecause (coraxinfo 666 777 888) (changeinfo abc def))
(simplecause (coraxinfo 666 111 222 777 333 444 555 888 999) (changeinfo abc 1a 2a 3a def 4a)))
(defrule cause_generalization_advanced_corax
?f1 <- (simplecause (coraxinfo $?coraxbefore1 ?coraxmatchafter $?) (changeinfo $?changebefore1))
?f2 <- (simplecause (coraxinfo $?coraxbefore2 ?coraxmatchafter $?) (changeinfo $?changebefore2))
(test (neq ?f1 ?f2))
(finalcause (coraxinfo $?finalcoraxbefore) (changeinfo $?finalchangebefore))
(test (and (subsetp $?finalcoraxbefore $?coraxbefore1) (subsetp $?finalcoraxbefore $?coraxbefore2)
(subsetp $?finalchangebefore $?changebefore1) (subsetp $?finalchangebefore $?changebefore2)))
=>
(assert (finalcause (coraxinfo $?finalcoraxbefore ?coraxmatchafter) (changeinfo $?finalchangebefore))))
(defrule cause_generalization_advanced_change
?f1 <- (simplecause (coraxinfo $?coraxbefore1) (changeinfo $?changebefore1 ?changematchafter $?))
?f2 <- (simplecause (coraxinfo $?coraxbefore2) (changeinfo $?changebefore2 ?changematchafter $?))
(test (neq ?f1 ?f2))
(finalcause (coraxinfo $?finalcoraxbefore) (changeinfo $?finalchangebefore))
(test (and (subsetp $?finalcoraxbefore $?coraxbefore1) (subsetp $?finalcoraxbefore $?coraxbefore2)
(subsetp $?finalchangebefore $?changebefore1) (subsetp $?finalchangebefore $?changebefore2)))
=>
(assert (finalcause (coraxinfo $?finalcoraxbefore) (changeinfo $?finalchangebefore ?changematchafter))))
(reset)
(run)
(facts)
f-0 (initial-fact)
f-1 (simplecause (coraxinfo 1 2 3) (changeinfo a b c))
f-2 (simplecause (coraxinfo 7 8 2 3 9) (changeinfo d a b e))
f-3 (simplecause (coraxinfo 2 3 10 13) (changeinfo f g a b z))
f-4 (simplecause (coraxinfo 77 88 99 66) (changeinfo k m l s))
f-5 (simplecause (coraxinfo 88 99 11 22) (changeinfo v k m w))
f-6 (simplecause (coraxinfo 13 88 99) (changeinfo k m))
f-7 (simplecause (coraxinfo 666 777 888) (changeinfo abc def))
f-8 (simplecause (coraxinfo 666 111 222 777 333 444 555 888 999) (changeinfo abc 1a 2a 3a def 4a))
f-9 (finalcause (coraxinfo 666) (changeinfo abc))
f-10 (finalcause (coraxinfo 666 888) (changeinfo abc))
f-11 (finalcause (coraxinfo 666 888) (changeinfo abc def))
f-12 (finalcause (coraxinfo 666 777) (changeinfo abc))
f-13 (finalcause (coraxinfo 666 777 888) (changeinfo abc))
f-14 (finalcause (coraxinfo 666 777 888) (changeinfo abc def))
f-15 (finalcause (coraxinfo 666 777) (changeinfo abc def))
f-16 (finalcause (coraxinfo 666) (changeinfo abc def))
f-17 (finalcause (coraxinfo 666) (changeinfo def))
f-18 (finalcause (coraxinfo 666 888) (changeinfo def))
f-19 (finalcause (coraxinfo 666 777) (changeinfo def))
f-20 (finalcause (coraxinfo 666 777 888) (changeinfo def))
f-21 (finalcause (coraxinfo 777) (changeinfo abc))
f-22 (finalcause (coraxinfo 777 888) (changeinfo abc))
f-23 (finalcause (coraxinfo 777 888) (changeinfo abc def))
f-24 (finalcause (coraxinfo 777) (changeinfo abc def))
f-25 (finalcause (coraxinfo 777) (changeinfo def))
f-26 (finalcause (coraxinfo 777 888) (changeinfo def))
f-27 (finalcause (coraxinfo 888) (changeinfo abc))
f-28 (finalcause (coraxinfo 888) (changeinfo abc def))
f-29 (finalcause (coraxinfo 888) (changeinfo def))
f-30 (finalcause (coraxinfo 88) (changeinfo k))
f-31 (finalcause (coraxinfo 88 99) (changeinfo k))
f-32 (finalcause (coraxinfo 88 99) (changeinfo k m))
f-33 (finalcause (coraxinfo 88) (changeinfo k m))
f-34 (finalcause (coraxinfo 88) (changeinfo m))
f-35 (finalcause (coraxinfo 88 99) (changeinfo m))
f-36 (finalcause (coraxinfo 99) (changeinfo k))
f-37 (finalcause (coraxinfo 99) (changeinfo k m))
f-38 (finalcause (coraxinfo 99) (changeinfo m))
f-39 (finalcause (coraxinfo 2) (changeinfo a))
f-40 (finalcause (coraxinfo 2 3) (changeinfo a))
f-41 (finalcause (coraxinfo 2 3) (changeinfo a b))
f-42 (finalcause (coraxinfo 2) (changeinfo a b))
f-43 (finalcause (coraxinfo 2) (changeinfo b))
f-44 (finalcause (coraxinfo 2 3) (changeinfo b))
f-45 (finalcause (coraxinfo 3) (changeinfo a))
f-46 (finalcause (coraxinfo 3) (changeinfo a b))
f-47 (finalcause (coraxinfo 3) (changeinfo b))

Apache Camel: Nested filters (filter ... filter ... end ...filter ... end ..end) in DSL (Groovy or Java)

we have some issues with the DSL for Camel Routes. It seems that it is not possible to translate the following XML Configuration into the Groovy (or JAVA) DSL
<route id="myroute" >
<from uri="fromURI" />
<filter>
<xpath>//entity[contains(#destinations, 'databasedestination')]</xpath>
<filter>
<xpath>//entity[#objectType = 'objectType']</xpath>
<camel:setHeader headerName="bodyTemp">
<simple>${body}</simple>
</camel:setHeader>
<filter>
<xpath>//entity[#command = 'add']</xpath>
<convertBodyTo type="com.foo.bar.Entity" />
<bean ref="handler" method="add" />
</filter>
<filter>
<xpath>//entity[#command = 'foo']</xpath>
<convertBodyTo type="com.foo.bar.Entity" />
<bean ref="handler" method="foo" />
</filter>
<filter>
<xpath>//entity[#command = 'bar']</xpath>
<convertBodyTo type="com.foo.bar.Entity" />
<bean ref="handler" method="bar" />
</filter>
<to uri="toURI" />
</filter>
</filter>
</route>
Wie tried to translate it inside a Groovy based RouteBuilder as follows:
from("fromURI")
.filter().xpath('//entity[contains(#destinations, \'databasedestination\')]')
.setHeader("bodyTemp", simple('${body}'))
.filter().xpath('//entity[#objectType = \'objectType\']')
.filter().xpath('//entity[#command = \'add\']')
.convertBodyTo(com.foo.bar.Entity)
.bean(handler, "add")
.end()
.filter().xpath('//entity[#command = \'foo\']')
.convertBodyTo(com.foo.bar.Entity)
.bean(handler, "foo")
.end()
.filter().xpath('//entity[#command = \'bar\']')
.convertBodyTo(com.foo.bar.Entity)
.bean(handler, "bar")
.end()
.to("toURI")
.end()
.end()
But that obviously doesn't work. We get a javax.xml.xpath.XPathExpressionException with the Message: Invalid xpath: //entity[#command = 'foo']
See the corresponding stacktrace as well.
->> 814 | doInEvaluateAs in org.apache.camel.builder.xml.XPathBuilder
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 697 | evaluateAs in ''
| 139 | matches . . . . . . in ''
| 47 | process in org.apache.camel.processor.FilterProcessor
| 73 | process . . . . . . in org.apache.camel.util.AsyncProcessorHelper
| 99 | processNext in org.apache.camel.processor.DelegateAsyncProcessor
| 90 | process . . . . . . in ''
| 73 | process in org.apache.camel.management.InstrumentationProcessor
| 99 | processNext . . . . in org.apache.camel.processor.DelegateAsyncProcessor
| 90 | process in ''
| 91 | process . . . . . . in org.apache.camel.processor.interceptor.TraceInterceptor
| 73 | process in org.apache.camel.util.AsyncProcessorHelper
| 330 | processErrorHandler in org.apache.camel.processor.RedeliveryErrorHandler
| 220 | process in ''
| 45 | processNext . . . . in org.apache.camel.processor.RouteContextProcessor
| 90 | process in org.apache.camel.processor.DelegateAsyncProcessor
| 303 | process . . . . . . in org.apache.camel.processor.interceptor.DefaultChannel
| 73 | process in org.apache.camel.util.AsyncProcessorHelper
| 117 | process . . . . . . in org.apache.camel.processor.Pipeline
| 80 | process in ''
| 45 | processNext . . . . in org.apache.camel.processor.RouteContextProcessor
| 90 | process in org.apache.camel.processor.DelegateAsyncProcessor
| 150 | processAsync . . . in org.apache.camel.processor.UnitOfWorkProcessor
| 117 | process in ''
| 48 | processNext . . . . in org.apache.camel.processor.RouteInflightRepositoryProcessor
| 90 | process in org.apache.camel.processor.DelegateAsyncProcessor
| 73 | process . . . . . . in org.apache.camel.util.AsyncProcessorHelper
| 99 | processNext in org.apache.camel.processor.DelegateAsyncProcessor
| 90 | process . . . . . . in ''
| 73 | process in org.apache.camel.management.InstrumentationProcessor
| 99 | process . . . . . . in org.apache.camel.util.AsyncProcessorHelper
| 86 | process in org.apache.camel.processor.DelegateAsyncProcessor
| 105 | onMessage . . . . . in org.apache.camel.component.jms.EndpointMessageListener
| 1110 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 603 | run . . . . . . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 722 | run in java.lang.Thread
Caused by XPathExpressionException: null
->> 200 | evaluate in com.sun.org.apache.xpath.internal.jaxp.XPathExpressionImpl
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 800 | doInEvaluateAs in org.apache.camel.builder.xml.XPathBuilder
| 697 | evaluateAs . . . . in ''
| 139 | matches in ''
| 47 | process . . . . . . in org.apache.camel.processor.FilterProcessor
| 73 | process in org.apache.camel.util.AsyncProcessorHelper
| 99 | processNext . . . . in org.apache.camel.processor.DelegateAsyncProcessor
| 90 | process in ''
| 73 | process . . . . . . in org.apache.camel.management.InstrumentationProcessor
| 99 | processNext in org.apache.camel.processor.DelegateAsyncProcessor
| 90 | process . . . . . . in ''
| 91 | process in org.apache.camel.processor.interceptor.TraceInterceptor
| 73 | process . . . . . . in org.apache.camel.util.AsyncProcessorHelper
| 330 | processErrorHandler in org.apache.camel.processor.RedeliveryErrorHandler
| 220 | process . . . . . . in ''
| 45 | processNext in org.apache.camel.processor.RouteContextProcessor
| 90 | process . . . . . . in org.apache.camel.processor.DelegateAsyncProcessor
| 303 | process in org.apache.camel.processor.interceptor.DefaultChannel
| 73 | process . . . . . . in org.apache.camel.util.AsyncProcessorHelper
| 117 | process in org.apache.camel.processor.Pipeline
| 80 | process . . . . . . in ''
| 45 | processNext in org.apache.camel.processor.RouteContextProcessor
| 90 | process . . . . . . in org.apache.camel.processor.DelegateAsyncProcessor
| 150 | processAsync in org.apache.camel.processor.UnitOfWorkProcessor
| 117 | process . . . . . . in ''
| 48 | processNext in org.apache.camel.processor.RouteInflightRepositoryProcessor
| 90 | process . . . . . . in org.apache.camel.processor.DelegateAsyncProcessor
| 73 | process in org.apache.camel.util.AsyncProcessorHelper
| 99 | processNext . . . . in org.apache.camel.processor.DelegateAsyncProcessor
| 90 | process in ''
| 73 | process . . . . . . in org.apache.camel.management.InstrumentationProcessor
| 99 | process in org.apache.camel.util.AsyncProcessorHelper
| 86 | process . . . . . . in org.apache.camel.processor.DelegateAsyncProcessor
| 105 | onMessage in org.apache.camel.component.jms.EndpointMessageListener
| 1110 | runWorker . . . . . in java.util.concurrent.ThreadPoolExecutor
| 603 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 722 | run . . . . . . . . in java.lang.Thread
Caused by TransformerException: Unable to evaluate expression using this context
->> 367 | execute in com.sun.org.apache.xpath.internal.XPath
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 129 | eval in com.sun.org.apache.xpath.internal.jaxp.XPathExpressionImpl
| 105 | eval . . . . . . . in ''
| 187 | evaluate in ''
| 800 | doInEvaluateAs . . in org.apache.camel.builder.xml.XPathBuilder
| 697 | evaluateAs in ''
| 139 | matches . . . . . . in ''
| 47 | process in org.apache.camel.processor.FilterProcessor
| 73 | process . . . . . . in org.apache.camel.util.AsyncProcessorHelper
| 99 | processNext in org.apache.camel.processor.DelegateAsyncProcessor
| 90 | process . . . . . . in ''
| 73 | process in org.apache.camel.management.InstrumentationProcessor
| 99 | processNext . . . . in org.apache.camel.processor.DelegateAsyncProcessor
| 90 | process in ''
| 91 | process . . . . . . in org.apache.camel.processor.interceptor.TraceInterceptor
| 73 | process in org.apache.camel.util.AsyncProcessorHelper
| 330 | processErrorHandler in org.apache.camel.processor.RedeliveryErrorHandler
| 220 | process in ''
| 45 | processNext . . . . in org.apache.camel.processor.RouteContextProcessor
| 90 | process in org.apache.camel.processor.DelegateAsyncProcessor
| 303 | process . . . . . . in org.apache.camel.processor.interceptor.DefaultChannel
| 73 | process in org.apache.camel.util.AsyncProcessorHelper
| 117 | process . . . . . . in org.apache.camel.processor.Pipeline
| 80 | process in ''
| 45 | processNext . . . . in org.apache.camel.processor.RouteContextProcessor
| 90 | process in org.apache.camel.processor.DelegateAsyncProcessor
| 150 | processAsync . . . in org.apache.camel.processor.UnitOfWorkProcessor
| 117 | process in ''
| 48 | processNext . . . . in org.apache.camel.processor.RouteInflightRepositoryProcessor
| 90 | process in org.apache.camel.processor.DelegateAsyncProcessor
| 73 | process . . . . . . in org.apache.camel.util.AsyncProcessorHelper
| 99 | processNext in org.apache.camel.processor.DelegateAsyncProcessor
| 90 | process . . . . . . in ''
| 73 | process in org.apache.camel.management.InstrumentationProcessor
| 99 | process . . . . . . in org.apache.camel.util.AsyncProcessorHelper
| 86 | process in org.apache.camel.processor.DelegateAsyncProcessor
| 105 | onMessage . . . . . in org.apache.camel.component.jms.EndpointMessageListener
| 1110 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 603 | run . . . . . . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 722 | run in java.lang.Thread
Caused by RuntimeException: Unable to evaluate expression using this context
->> 266 | setRoot in com.sun.org.apache.xpath.internal.axes.NodeSequence
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 214 | execute in com.sun.org.apache.xpath.internal.axes.LocPathIterator
| 339 | execute . . . . . . in com.sun.org.apache.xpath.internal.XPath
| 129 | eval in com.sun.org.apache.xpath.internal.jaxp.XPathExpressionImpl
| 105 | eval . . . . . . . in ''
| 187 | evaluate in ''
| 800 | doInEvaluateAs . . in org.apache.camel.builder.xml.XPathBuilder
| 697 | evaluateAs in ''
| 139 | matches . . . . . . in ''
| 47 | process in org.apache.camel.processor.FilterProcessor
| 73 | process . . . . . . in org.apache.camel.util.AsyncProcessorHelper
| 99 | processNext in org.apache.camel.processor.DelegateAsyncProcessor
| 90 | process . . . . . . in ''
| 73 | process in org.apache.camel.management.InstrumentationProcessor
| 99 | processNext . . . . in org.apache.camel.processor.DelegateAsyncProcessor
| 90 | process in ''
| 91 | process . . . . . . in org.apache.camel.processor.interceptor.TraceInterceptor
| 73 | process in org.apache.camel.util.AsyncProcessorHelper
| 330 | processErrorHandler in org.apache.camel.processor.RedeliveryErrorHandler
| 220 | process in ''
| 45 | processNext . . . . in org.apache.camel.processor.RouteContextProcessor
| 90 | process in org.apache.camel.processor.DelegateAsyncProcessor
| 303 | process . . . . . . in org.apache.camel.processor.interceptor.DefaultChannel
| 73 | process in org.apache.camel.util.AsyncProcessorHelper
| 117 | process . . . . . . in org.apache.camel.processor.Pipeline
| 80 | process in ''
| 45 | processNext . . . . in org.apache.camel.processor.RouteContextProcessor
| 90 | process in org.apache.camel.processor.DelegateAsyncProcessor
| 150 | processAsync . . . in org.apache.camel.processor.UnitOfWorkProcessor
| 117 | process in ''
| 48 | processNext . . . . in org.apache.camel.processor.RouteInflightRepositoryProcessor
| 90 | process in org.apache.camel.processor.DelegateAsyncProcessor
| 73 | process . . . . . . in org.apache.camel.util.AsyncProcessorHelper
| 99 | processNext in org.apache.camel.processor.DelegateAsyncProcessor
| 90 | process . . . . . . in ''
| 73 | process in org.apache.camel.management.InstrumentationProcessor
| 99 | process . . . . . . in org.apache.camel.util.AsyncProcessorHelper
| 86 | process in org.apache.camel.processor.DelegateAsyncProcessor
| 105 | onMessage . . . . . in org.apache.camel.component.jms.EndpointMessageListener
| 1110 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 603 | run . . . . . . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 722 | run in java.lang.Thread
Thank you for any help
Markus
Your code seems to be more fitting for a Content Based Router, making use of the choice EIP.
Are you able to make use of a choice statement instead? http://camel.apache.org/content-based-router.html

Code golf: the Mandelbrot set

Locked. This question and its answers are locked because the question is off-topic but has historical significance. It is not currently accepting new answers or interactions.
Usual rules for the code golf. Here is an implementation in python as an example
from PIL import Image
im = Image.new("RGB", (300,300))
for i in xrange(300):
print "i = ",i
for j in xrange(300):
x0 = float( 4.0*float(i-150)/300.0 -1.0)
y0 = float( 4.0*float(j-150)/300.0 +0.0)
x=0.0
y=0.0
iteration = 0
max_iteration = 1000
while (x*x + y*y <= 4.0 and iteration < max_iteration):
xtemp = x*x - y*y + x0
y = 2.0*x*y+y0
x = xtemp
iteration += 1
if iteration == max_iteration:
value = 255
else:
value = iteration*10 % 255
print value
im.putpixel( (i,j), (value, value, value))
im.save("image.png", "PNG")
The result should look like this
Use of an image library is allowed. Alternatively, you can use ASCII art. This code does the same
for i in xrange(40):
line = []
for j in xrange(80):
x0 = float( 4.0*float(i-20)/40.0 -1.0)
y0 = float( 4.0*float(j-40)/80.0 +0.0)
x=0.0
y=0.0
iteration = 0
max_iteration = 1000
while (x*x + y*y <= 4.0 and iteration < max_iteration):
xtemp = x*x - y*y + x0
y = 2.0*x*y+y0
x = xtemp
iteration += 1
if iteration == max_iteration:
line.append(" ")
else:
line.append("*")
print "".join(line)
The result
********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************
**************************************** ***************************************
**************************************** ***************************************
**************************************** ***************************************
**************************************** ***************************************
**************************************** ***************************************
**************************************** ***************************************
**************************************** ***************************************
*************************************** **************************************
************************************* ************************************
************************************ ***********************************
*********************************** **********************************
************************************ ***********************************
************************************* ************************************
*********************************** **********************************
******************************** *******************************
**************************** ***************************
***************************** ****************************
**************************** ***************************
************************ * * ***********************
*********************** * * **********************
******************** ******* ******* *******************
**************************** ***************************
****************************** *****************************
***************************** * * * ****************************
********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************
Edit:
Rules for the ASCII art:
size in rows/columns is parametrized and the code must work with any valid value.
at least three level of differentiation in density depending on the iteration count (so my prototype up there is not compliant)
oriented horizontally (so my prototype up there is not compliant)
critical parameters are fixed (max iteration = 1000, runaway value xx + yy <= 4.0)
Rules for the graphic:
size in rows/columns is parametrized and the code must work with any valid value.
at least three level of colors, gray scale
oriented horizontally (my prototype is compliant)
There was a perl solution already some years ago
posted in perlmonks, it reads:
#!/usr/bin/perl
$r=25; $c=80;
$xr=6;$yr=3;$xc=-0.5;$dw=$z=-4/
100;local$";while($q=$dr=rand()
/7){$w+=$dw;$_=join$/,map{$Y=$_*
$yr/$r;
join"" ,map{$ x=$_*$
xr/$c;($ x,$y)= ($xc+$x
*cos($ w)-$Y* sin$w,$yc+
$x*sin ($w)+$Y*cos
$w);$ e=-1;$ a=$b=0
;($a,$b) =($u-$v+$x,2*$a* $b+$y) while(
$ u=$a*$ a)+($v=$b*$b)<4.5 &&++$e <15;if (($e>$
q&&$e< 15)||($e==$q and rand() <$dr)) {$q=$e;($d0,$d1) =($x,$
y); } chr(+( 32,96,+ 46,45,43,58,73,37 ,36,64
,32)[$ e/1.5] );}(-$ c/2)..($c/2)-1;} (-$r/2
)..($ r/2)-1;select$", $",$", 0.015; system
$^O=~m ~[wW]in~x?"cls": "clear";print ;$xc=(
$d0+15 *$xc)/16;$yc=($ d1+15*$yc)/ 16;$_*=
1+$z for $xr,$yr;$dw *=-1 if rand
()<0.02; (++$i%110 )||($z*=-1)}
which is a "Mandelbrot explorer".
(It rotates, zooms in & out, and scrolls randomly to examine regions
of the Mandelbrot set it deems "interesting.", according to
it's creator.)
It doesn't exactly follow the specs named here but
makes an interesting entry (imho). Maybe a simple
Mandlebrot is not very interesting for the perl gods ;.-)
Regards
rboo
J, greyscale graphical output with levels, 170 characters.
load'viewmat'
c=:>(<:;|:;0$])((2$>:#+:)$-:%~i:)300
(2.5*|:3 99$i._99)viewmat {:99&<.#;#(({:+4&<#:({.+1&{)#:*:);~(0{c)&+#({.-1&{)#:*:,:(1{c)&+#:+:#({.*1&{))^:99 c
alt text http://i40.tinypic.com/2i7lm0.jpg
J, graphical output with levels, 151 characters.
load'viewmat'
c=:>(<:;|:;0$])((2$>:#+:)$-:%~i:)99
viewmat {:99&<.#;#(({:+4&<#:({.+1&{)#:*:);~(0{c)&+#({.-1&{)#:*:,:(1{c)&+#:+:#({.*1&{))^:99 c
Output:
alt text http://i40.tinypic.com/6ynxap.jpg
J, graphical output, 124 characters.
load'viewmat'
c=:>(<:;|:)((2$>:#+:)$-:%~i:)200
viewmat 4>:({.+{:)#:*:(5<.>#(({.c)&+#({.-{:)#:*:;({:c)&+#:+:#({.*{:)))^:999 c
Basically just runs "viewmat" on the ascii output.
alt text http://i40.tinypic.com/etv5lf.jpg
J, ASCII, 101 characters.
c=:>(<:;|:)((2$>:#+:)$-:%~i:)20
4>:({.+{:)#:*:(5<.>#(({.c)&+#({.-{:)#:*:;({:c)&+#:+:#({.*{:)))^:999 c
Wasted 6 characters to properly parametrize the size.
J, ASCII, 95 characters.
c=:>(<:;|:)41 41$10%~i:20
4>:({.+{:)#:*:(5<.>#(({.c)&+#({.-{:)#:*:;({:c)&+#:+:#({.*{:)))^:999 c
It doesn't do multiple levels of greyscale yet.
Explanation (currently out of date, will update later):
i:20
Generate the list of integers from -20 to 20.
10%~i:20
Divide them all by 10 (% is divide, ~ is invert order of arguments.
41 41$10%~i:20
Fill this list into a 41x41 array, with wrapping.
(-&1;|:)41 41$`10%~i:20`
Append to this array a second array of the same size, but transposed. -&1 subtracts one from each element, ; is append, |: is transpose. Now we have a 2x41x41 array, where the first 41x41 array contains the "x0" values of each coordinate and the second contains the "y0" values.
4<:~({.+{:)#:*:(5<.>#(({.c)&+#:({.-{:)#:*:;({:c)&+#:+:#:({.*{:)))^:1000 ($c)$0
Wow. Let's break this up from the right.
($c)$0
This creates a second 2x41x41 array (the same size as c), filled with 0s. This is going to be the variable we're iterating on - basically the first array contains the "x" values and the second contains the "y" values.
^:1000 means "Repeat the previous thing in parentheses 1000 times. This is our loop counter.
(5<.>#(({.c)&+#:({.-{:)#:*:;({:c)&+#:+:#:({.*{:))
This is the next big chunk. It's basically doing one iteration of the loop. First we generate x with (({.c)&+#:({.-{:)#:*:, then join ; it to y ({:c)&+#:+:#:({.*{:)
(({.c)&+#:({.-{:)#:*:
This generates x (remember it's operating on that 2x41x41 array representing x and y). First it squares *: each element, then does {. - {:, or x^2 - y^2. {. selects the first 41x41 array and {: the second. #: joins functions together.
To x^2-y^2, we need to add x0 - this is the first 41x41 array of c so we can do this with ({.c)&+ - & curries {.c (x0) into +.
({:c)&+#:+:#:({.*{:)
We generate y in a similar fashion. First we pairwise multiply the input x {. and y {: arrays, double the result with +:, and add y0 {:c.
The last step of this function is simply 5<.> - unboxing the join of the two new x and y arrays, and capping at 5 - it's ok since this function is monotonically increasing above 4, and we'll get out-of-bounds integers if we don't cap the values on each iteration.
4>:({.+{:)#:*:
The last step, once we've finished iterating. We square the x and y arrays *:, add them together {.+{:, and make a boolean array that's true for every element that's >: less than 4.
Output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 1 1 1 1 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 1 1 1 1 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Python 108 (was 122):
for a in range(900):print"\n.x"[(a%30>0)+(abs(reduce(lambda z,c:z*z+c,[a%30*.1-2+1j*(a/30*.1-1.5)]*30))<2)],
That last "30" is the iteration count, not one of the dimensions.
Output looks thus:
. . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . x . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . x x . . . . . . . . . .
. . . . . . . . . . . . . . . . . x x . . . . . . . . . .
. . . . . . . . . . . . . . x . x x x x x . . . . . . . .
. . . . . . . . . . . . . . x x x x x x x x x . . . . . .
. . . . . . . . . . . . . x x x x x x x x x x . . . . . .
. . . . . . . . . x . . . x x x x x x x x x x . . . . . .
. . . . . . . . x x x . x x x x x x x x x x x x . . . . .
. . . . . . . x x x x x x x x x x x x x x x x . . . . . .
x x x x x x x x x x x x x x x x x x x x x x . . . . . . .
. . . . . . . x x x x x x x x x x x x x x x x . . . . . .
. . . . . . . . x x x . x x x x x x x x x x x x . . . . .
. . . . . . . . . x . . . x x x x x x x x x x . . . . . .
. . . . . . . . . . . . . x x x x x x x x x x . . . . . .
. . . . . . . . . . . . . . x x x x x x x x x . . . . . .
. . . . . . . . . . . . . . x . x x x x x . . . . . . . .
. . . . . . . . . . . . . . . . . x x . . . . . . . . . .
. . . . . . . . . . . . . . . . . x x . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . x . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Now going to update based on the updated rules....
Haskell (185 chars, with all the features required in the question)
Using complex numbers and actually counting the required number of iterations (unlike the "simple" version in my other answer).
import Complex
i v=show(length$takeWhile((<=4).magnitude)$take 1000$iterate(\c->c*c+v)v)!!0
r t=[-2,4/read t-2..2]
main=getLine>>=(\[s,t]->mapM_ putStrLn[[i$x:+y|x<-r s]|y<-r t]).words
The dimensions of the resulting image are read from stdin. The output is "colored" according to the number of required iterations:
$ ./fract
60 30
1111111111111111111111111111111111111111111111111111111111111
1111111111111112222222222222222111111111111111111111111111111
1111111112222222222222222222222222222111111111111111111111111
1111112222222222222222222222222222222222111111111111111111111
1112222222222222222222222222222222222222222111111111111111111
1222222222222222222222333333333322222222222221111111111111111
2222222222222222223333333344443333332222222222211111111111111
2222222222222233333333344458755443333322222222222111111111111
2222222222233333333344445568117544433333222222222211111111111
2222222233333333344445556711111765544333322222222221111111111
2222233333333444445562391112161568786443332222222222111111111
2223333334444455556681111111111111157544333222222222211111111
2333334445617677777911111111111111111854333222222222211111111
3333444456681131231111111111111111111654333322222222221111111
3444555671111111111111111111111111114644333322222222221111111
2569888111111111111111111111111111296544333322222222221111111
3444555671111111111111111111111111114644333322222222221111111
3333444456681131231111111111111111111654333322222222221111111
2333334445617677777911111111111111111854333222222222211111111
2223333334444455556681111111111111157544333222222222211111111
2222233333333444445562391112161568786443332222222222111111111
2222222233333333344445556711111765544333322222222221111111111
2222222222233333333344445568117544433333222222222211111111111
2222222222222233333333344458755443333322222222222111111111111
2222222222222222223333333344443333332222222222211111111111111
1222222222222222222222333333333322222222222221111111111111111
1112222222222222222222222222222222222222222111111111111111111
1111112222222222222222222222222222222222111111111111111111111
1111111112222222222222222222222222222111111111111111111111111
1111111111111112222222222222222111111111111111111111111111111
1111111111111111111111111111111111111111111111111111111111111
Delphi - 310 249 239 224 chars
ASCII version. Uses 7 levels for gradient shading.
Removed program P; and {$APPTYPE CONSOLE} according to (suggested by Uwe Raabe);
Inlined 1000 const (suggested by Uwe Raabe);
Inlined '8Oo;,. ' variable;
Changed word to integer so that the loop variable can be negative, and then changed the loop range for I from 3..38 to -5..30 so that (I-8) could be replaced by I (suggested by Eric Grange);
Changed 1000 to 1e3 (suggested by Eric Grange)
Changed type Double to Real (suggested by Luc Neville via e-mail)
Removed brackets while((x*x+y*y<=4)and(t<1000))do --> while(x*x+y*y<=4)and(t<1000)do (suggested by Luc Neville via e-mail)
Removed spaces between numbers that were followed by a keyword (so that for j:=-5 to 30 do becomes for j:=-5to 30do(Suggested by Neville via e-mail)
Changed loop range to for j:=8to 40do, removing the negative sign, and changed integer back to word. Compensated this offset in the formula, by changing x * x - y * y + i / 16 - 2; to x * x - y * y + i / 16 - 3;
Unreadable version:
var n,x,y:Real;t,i,j:Word;begin for j:=8to 40do begin for i:=8to 65do begin x:=0;y:=0;t:=0;while(x*x+y*y<=4)and(t<1e3)do begin n:=x*x-y*y+i/16-3;y:=2*x*y+j/12-2;x:=n;inc(t)end;Write('8Oo;,. '[t mod 7+1])end;WriteLn;end;end.
Formatted code:
var
n, x, y: Real;
t, i, j: Word;
begin
for j := 8 to 40 do
begin
for i := 8 to 65 do
begin
x := 0;
y := 0;
t := 0;
while (x * x + y * y <= 4) and (t < 1e3) do
begin
n := x * x - y * y + i / 16 - 3;
y := 2 * x * y + j / 12 - 2;
x := n;
inc(t)
end;
Write('8Oo;,. '[t mod 7 + 1])
end;
WriteLn;
end;
end.
Output:
OOOOOOOOOOOOOOOOOooooooooooooooooooooooooooooooooooooooooo
OOOOOOOOOOOOOOOOooooooooo;;;;;;;;;;;;;;;oooooooooooooooooo
OOOOOOOOOOOOOOOoooooo;;;;;;;;;;;;;;,,,,,;;;;oooooooooooooo
OOOOOOOOOOOOOOooooo;;;;;;;;;;;;;,,,, ; .,,,;;;oooooooooooo
OOOOOOOOOOOOOoooo;;;;;;;;;;;;;,,,,.. O ,,,,;;;oooooooooo
OOOOOOOOOOOOooo;;;;;;;;;;;;;,,,,,...8oo,8..,,,;;;;oooooooo
OOOOOOOOOOOooo;;;;;;;;;;;;,,,,,,.. Oo. ; 8...,,;;;;ooooooo
OOOOOOOOOOOoo;;;;;;;;;;;;,,,,,. 8OO O8 ..,,;;;;oooooo
OOOOOOOOOOoo;;;;;;;;;;;,,,,.. O,oO8oo ,OOoO88,.,;;;;ooooo
OOOOOOOOOOo;;;;;;;;;;,,,.... o. . OOO ,;;;;;oooo
OOOOOOOOOO;;;;;;;;;,,...... o., o .,;;;;;ooo
OOOOOOOOOo;;;;;;,,. o 88O. ;O.,;;;;;ooo
OOOOOOOOO;;;,,,,,.. ,,o;,oOo; o ,,;;;;;oo
OOOOOOOOO;,,,,,... 8o; 8;, .,,;;;;;oo
OOOOOOOOO,,,,,... Oo . 8.,,;;;;;oo
OOOOOOOOO,.,. 88oo o , , .,,;;;;;oo
OOOOOOOO ,8 .,,;;;;;;o
OOOOOOOOO,.,. 88oo o , , .,,;;;;;oo
OOOOOOOOO,,,,,... Oo . 8.,,;;;;;oo
OOOOOOOOO;,,,,,... 8o; 8;, .,,;;;;;oo
OOOOOOOOO;;;,,,,,.. ,,o;,oOo; o ,,;;;;;oo
OOOOOOOOOo;;;;;;,,. o 88O. ;O.,;;;;;ooo
OOOOOOOOOO;;;;;;;;;,,...... o., o .,;;;;;ooo
OOOOOOOOOOo;;;;;;;;;;,,,.... o. . OOO ,;;;;;oooo
OOOOOOOOOOoo;;;;;;;;;;;,,,,.. O,oO8oo ,OOoO88,.,;;;;ooooo
OOOOOOOOOOOoo;;;;;;;;;;;;,,,,,. 8OO O8 ..,,;;;;oooooo
OOOOOOOOOOOooo;;;;;;;;;;;;,,,,,,.. Oo. ; 8...,,;;;;ooooooo
OOOOOOOOOOOOooo;;;;;;;;;;;;;,,,,,...8oo,8..,,,;;;;oooooooo
OOOOOOOOOOOOOoooo;;;;;;;;;;;;;,,,,.. O ,,,,;;;oooooooooo
OOOOOOOOOOOOOOooooo;;;;;;;;;;;;;,,,, ; .,,,;;;oooooooooooo
OOOOOOOOOOOOOOOoooooo;;;;;;;;;;;;;;,,,,,;;;;oooooooooooooo
OOOOOOOOOOOOOOOOooooooooo;;;;;;;;;;;;;;;oooooooooooooooooo
OOOOOOOOOOOOOOOOOooooooooooooooooooooooooooooooooooooooooo
T-SQL (421 408 characters)
declare #s varchar(max);
with
x(x)as(select CAST(-2.0 as real)union all select x+.01 from x where x<1),
y(y)as(select CAST(-1.1 as real)union all select y+.02 from y where y<1.1),
g(x,y,u,v,g)as(select x,y,x*0,y*0,0 from x,y union all select x,y,u*u-v*v+x,2*u*v+y,g+1 from g where g<24and u*u+v*v<4),
m(x,y,v)as(select x,y,case when x<-1.99 then char(10)end+substring(' .-''^"+oiexp**##$$$§§%%%#',COUNT(*),1)from g group by x,y)
select #s=#s+v from m order by y,x option(maxrecursion 400)
select #s
Output is here:
awk - 134 135 chars
ASCII art, fully compliant. Fairly straightforward translation of the python reference implementation:
{for(j=-2;j<=2;j+=4/$2){for(i=-3;i<=1;i+=4/$1){for(x=y=k=0;x*x+y*y<=4&&++k<4^5;)
{t=x*x-y*y+i;y=2*x*y+j;x=t}printf"%d",log(k)}print""}}
test run
$ awk -f mandel.awk
10 10
00000000000
00000000000
00000111000
00001116110
00011166610
00046666611
00011166610
00001116110
00000111000
00000000000
00000000000
and this is a VT-100 art. Set the xterm to "unreadable" characters, then try a 400x200 set:
{for(j=-2;j<=2;j+=4/$2){for(i=-3;i<=1;i+=4/$1){for(x=y=k=0;x*x+y*y<=4&&++k<1000;)
{t=x*x-y*y+i;y=2*x*y+j;x=t}printf"\x1b[4%dm ",log(k)}print"\x1b[0m"}}
Haskell (162 characters)
A (fairly) straight forward ASCII art version:
c(x,y)|x*x+y*y<4.0='x'
|True='.'
i v w=c(iterate s(v,w)!!1000)where s(x,y)=(x*x-y*y+v,2*x*y+w)
main=mapM_ putStrLn[[i x y|x<-[-1.5,-1.45..0.5]]|y<-[1,0.9.. -1]]
Output:
$ ./a.out
.........................................
.........................................
..........................xxxx...........
..........................xxxx...........
....................x..xxxxxxxxxx........
....................xxxxxxxxxxxxxxxxx....
..................xxxxxxxxxxxxxxxxxxx....
.................xxxxxxxxxxxxxxxxxxxxx...
.......xxxxxxx..xxxxxxxxxxxxxxxxxxxxxx...
......xxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxx...
..xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.....
......xxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxx...
.......xxxxxxx..xxxxxxxxxxxxxxxxxxxxxx...
.................xxxxxxxxxxxxxxxxxxxxx...
..................xxxxxxxxxxxxxxxxxxx....
....................xxxxxxxxxxxxxxxxx....
....................x..xxxxxxxxxx........
..........................xxxx...........
..........................xxxx...........
.........................................
.........................................
More readable version:
outchar (x,y)
| x*x + y*y < 4.0 = 'x'
| otherwise = '.'
calc v w = outchar (iterate step (v,w) !! 1000)
where step (x,y) = (x*x - y*y + v, 2*x*y + w)
main = mapM_ putStrLn [[calc x y
| x <- [-1.5, -1.45 .. 0.5]]
| y <- [1, 0.9 .. -1]]
Python 197 162
def m():
for a in range(900):
c=complex(a%30*.1-2,a/30*.1-1.5);z,i=c-c,0
while i<28 and abs(z)<2:z,i=z*z+c,i+1
if a%30==0:print
print ".-+oxawOX "[i/3],
I'm interested in how you get rid of the white space in python.
Assembler
.COM Executable = 140 bytes
Source = 652 bytes
mov ax,13h
int 10h
mov bx,200
xor di,di
mov ax,0a000h
mov es,ax
l1:mov bp,320
mov [si],bx
fild w[si]
fisub w[v100]
fidiv w[v50]
l2:mov cx,1000
mov [si],bp
fild w[106h]
fisub w[si]
fidiv w[v80]
fld1
fsubp
fldz
fldz
l3:fld st(1)
fmul st(0)
fld st(1)
fmul st(0)
fld st(0)
fadd st(2)
fcomp d[v4]
fstsw ax
test ah,45h
jz l4
fsubp
fadd st(3)
fxch st(2)
fild w[v2]
fmulp st(1)
fmulp st(1)
fadd st(3)
loop l3
mov al,255
l5:fcompp
fcomp
stosb
dec bp
jnz l2
fcomp
dec bx
jnz l1
mov ah,7
int 21h
mov ax,3
int 10h
ret
l4:mov ax,-10
mul cx
fcompp
jmp l5
v100:dw 100
v50:dw 80
v80:dw 90
v4:dd 4.0
v2:dw 2
JavaScript (168/174 characters)
Rhino version (168 characters):
m=1000;for(i=0;i<40;i++){l=[];for(j=0;j<80;j++){v=j/80*3-2,w=2-i/40*3,x=y=c=0;while(x*x+y*y<5&&c<m)t=x*x-y*y+v,y=2*x*y+w,x=t,c++;l.push(c==m?' ':'-')}print(l.join(''))}
Firebug version (174 characters):
m=1000;for(i=0;i<40;i++){l=[];for(j=0;j<80;j++){v=j/80*3-2,w=2-i/40*3,x=y=c=0;while(x*x+y*y<5&&c<m)t=x*x-y*y+v,y=2*x*y+w,x=t,c++;l.push(c==m?' ':'-')}console.log(l.join(''))}
And a dc entry - 152 chars
My usual madness in dc
Ak?4r/sa4r/sbA00sm[0*]sG_2sj[_3si[0ddsxsysk[lxd*lyd*-li+2lxly**lj+sysx1lxd*lyd*+
4!>G1lk1+dsklm<G*1=L]dsLx0klk1-vvnAklila+dsi1!<I]dsIxAPljlb+dsj2!<J]dsJx
test run:
bash-3.2$ dc -f mandel.dc
10 20
000000000000000000000
000000000011111111111
000000001111111111111
000000111111115211111
000000111111555551111
000000555555555551111
000000111111555551111
000000111111115211111
000000001111111111111
000000000011111111111
000000000000000000000
Ruby - 139 chars (Twitter-friendly)
b,a=$*;a.to_i.times{|l|puts (0..b.to_i).map{|n|x=y=i=0;(x,y,i=x*x-y*y+n/38.0-1.5,2*x*y+l/14.0-1,i+1)until(x*x+y*y>4||i>78);(32+i).chr}*""}
$ ruby mandelbrot.rb 80 32
or as a single command line (134 chars including ruby -e)
ruby -e "32.times{|l|puts (0..78).map{|n|x=y=i=0;(x,y,i=x*x-y*y+n/38.0-1.5,2*x*y+l/14.0-1,i+1)until(x*x+y*y>4||i>78);(32+i).chr}*''}"
"###############################$$$$$$$$$$$%%%%&&')*/))*.o&%$$$$$$$$########"""""
############################$$$$$$$$$$$$$%%%%%&''((*-G,*('&&%%$$$$$$$$$########""
#########################$$$$$$$$$$$$$%%%%%&&'929-03ooL.+0:'&%%%%%$$$$$$$########
#####################$$$$$$$$$$$$$$%%%&&&&&''()-1oooooooo/*('&&%%%%%%%$$$$$######
##################$$$$$$$$$$$$%%%&'''''''''())*,6oooooooo.*)((''&&&&&&&&%$$$#####
###############$$$$$$$$$%%%%%%&&'(+3:0.,++ooE6ooooooooooo?8o1j?8)(((()4/'&%$$$###
###########$$$$$$%%%%%%%%%%&&&&''(*1>ooo8oooooooooooooooooooooooo.3oooD/,'%%$$$##
#######$$$$%%%%%%%%%%%%%&&&&&&')8,,17ooooooooooooooooooooooooooooooooQ0)'&&%%$$$#
$$$$$$%&)(&&&&&&&&&&&&&&&'''((*18oooooooooooooooooooooooooooooooooooool*(('&%%$$$
$$%%%%&&*2*))((((25*(('''((()+F>=oooooooooooooooooooooooooooooooooooooooo1.(%%$$$
%%%%%&&'()*,1o47//5o5/?,+***+3oooooooooooooooooooooooooooooooooooooooooo.)(&%%$$$
%%%%&'''(*+-3ooooooooooom//-.oooooooooooooooooooooooooooooooooooooooooooo9+&%%$$$
&&(*+)))+-?ooooooooooooooooL5ooooooooooooooooooooooooooooooooooooooooooo8)&%%%$$$
'()*-X=U95ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo*'&&%%%$$$
ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo:.+)('&&%%%$$$
'()*-X=U95ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo*'&&%%%$$$
&&(*+)))+-?ooooooooooooooooL5ooooooooooooooooooooooooooooooooooooooooooo8)&%%%$$$
%%%%&'''(*+-3ooooooooooom//-.oooooooooooooooooooooooooooooooooooooooooooo9+&%%$$$
%%%%%&&'()*,1o47//5o5/?,+***+3oooooooooooooooooooooooooooooooooooooooooo.)(&%%$$$
$$%%%%&&*2*))((((25*(('''((()+F>=oooooooooooooooooooooooooooooooooooooooo1.(%%$$$
$$$$$$%&)(&&&&&&&&&&&&&&&'''((*18oooooooooooooooooooooooooooooooooooool*(('&%%$$$
#######$$$$%%%%%%%%%%%%%&&&&&&')8,,17ooooooooooooooooooooooooooooooooQ0)'&&%%$$$#
###########$$$$$$%%%%%%%%%%&&&&''(*1>ooo8oooooooooooooooooooooooo.3oooD/,'%%$$$##
###############$$$$$$$$$%%%%%%&&'(+3:0.,++ooE6ooooooooooo?8o1j?8)(((()4/'&%$$$###
##################$$$$$$$$$$$$%%%&'''''''''())*,6oooooooo.*)((''&&&&&&&&%$$$#####
#####################$$$$$$$$$$$$$$%%%&&&&&''()-1oooooooo/*('&&%%%%%%%$$$$$######
#########################$$$$$$$$$$$$$%%%%%&&'929-03ooL.+0:'&%%%%%$$$$$$$########
############################$$$$$$$$$$$$$%%%%%&''((*-G,*('&&%%$$$$$$$$$########""
"###############################$$$$$$$$$$$%%%%&&')*/))*.o&%$$$$$$$$########"""""
"""""###############################$$$$$$$$$%%%&'*)'&&%%%$$$$$$$#######"""""""""
"""""""""#################################$$$$$$$%%%%%$$$$$#########"""""""""""""
""""""""""""""""#############################################""""""""""""""""""""
Python. 98 chars.
for _ in range(526):z=0;exec"z=z*z+_%25*.1-2+_/25*.1j-1j;"*50;print[".#"[z.real<4],"\n"][_%25<1],
Prints something like this:
. . . . . . . . . . . . . . . . . . . # . . . .
. . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . # # . . . . .
. . . . . . . . . . . . . . . . . # # . . . . .
. . . . . . . . . . . . . . # . # # # # # . . .
. . . . . . . . . . . . . . # # # # # # # # # .
. . . . . . . . . . . . . # # # # # # # # # # .
. . . . . . . . . . . . . # # # # # # # # # # .
. . . . . . . . # # # . # # # # # # # # # # # .
. . . . . . . # # # # # # # # # # # # # # # # .
# # # # # # # # # # # # # # # # # # # # # # . .
. . . . . . . # # # # # # # # # # # # # # # # .
. . . . . . . . # # # . # # # # # # # # # # # .
. . . . . . . . . . . . . # # # # # # # # # # .
. . . . . . . . . . . . . # # # # # # # # # # .
. . . . . . . . . . . . . . # # # # # # # # # .
. . . . . . . . . . . . . . # . # # # # # . . .
. . . . . . . . . . . . . . . . . # # . . . . .
. . . . . . . . . . . . . . . . . # # . . . . .
. . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . # . . . .
http://codepad.org/rNPrgQ3H
C# - 330
277 if you drop the using statement and remove the leading whitespace and line endings
int c,i,j,w=300,h=300,m=50;
using(var b=new Bitmap(w,h)){
for(i=0;i<w;i++){
for(j=0;j<h;j++){
double x0=4.0*(i-w/2)/w-1,y0=4.0*(j-h/2)/h,x=0.0,y=0.0;
for(c=0;x*x+y*y<=4.0&&c<m;c++){
var t=x*x-y*y+x0;
y=2.0*x*y+y0;x=t;
}
int v=c==m?255:c*10%255;
b.SetPixel(i,j,Color.FromArgb(v,v,v));
}
}
}
Not record setting by a long shot - but fun to convert from the Python sample source and compress down beyond readable.

Resources