Skip to main content

Posts

NumberCheck in haskell

import System.Environment import Data.Char main = do arg:_ putStrLn (arg ++ " is " ++ (result arg)) where result arg = if check arg then "correct" else "incorrect" check arg = dotOrDigit `all` arg && oneOrZeroDots arg dotOrDigit = (`elem` ['0'..'9'] ++ ['.']) oneOrZeroDots = (

logs display, little experiment

this code ... module LogDiffMarker where type ReferenceWords = [String] type Lines = [Line] type Line = String mark_diffrent_words :: (ReferenceWords, Lines) -> Line -> (ReferenceWords, Lines) mark_diffrent_words (ref,i) line = (next_ref, i ++ [unwords line_with_em]) where (line_with_em, next_ref) = mark_diffrences (words line) ref ([],[]) mark_diffrences l1 [] (line_acc, ref_acc) = (line_acc ++ ["<b>"] ++ l1 ++ ["</b>"], ref_acc ++ l1) mark_diffrences [] r (line_acc, ref_acc) = (line_acc, ref_acc) mark_diffrences (h1:t1) (h2:t2) (line_acc, ref_acc) | h1 == h2 = mark_diffrences t1 t2 (line_acc ++ [h1] ,ref_acc ++ [h2]) | otherwise = mark_diffrences t1 t2 (line_acc ++ ["<b>" ++ h1 ++ "</b>"],ref_acc ++ [h1]) mark_diffrent_lines :: Lines -> Lines mark_diffrent_lines = (["<pre>"]++) . (++["</pre>"]) . snd . (f...

functional music, honorable mention of new composer C.W. Boese

just after the previous post a talented composer (Boese) used the small framework for functional music in haskell for one of his compisitions. His work balances harmony and disharmony in an unbalanced way and thereby balances the unbalancing and balancing forces driving the excellent piece of modern algorithmic music. with his silent permission the source as well the interpretation is attached to this post. Here's the interpretation using an artifical Clarinet: play . Here's the source: boeseboese = Rest (2/4) :+: (hochlauf (-2) 3 boese) :=: (hochlauf (2) 3 boese) :+: boese boese = rpt 3 freak :=: rpt 3 ghoul :=: rpt 3 funk grund = (Note (Cis,5) 1) freak = rptm (Trans (round (abs (duration ghoul)))) 3 funk ghoul = akkord grund 0 funk = Trans terz grund :=: rptm (Trans quinte) 4 ghoul just append that to the previous program and adapt the main function. Maybe it's also worth mentioning, that this was the first piece of haskell code written by him. Haskell syntax helps to cre...

Learning Haskell, functional music

As you might have realized, I started to learn Haskell. One of the most fun things to do in any programming language is creating some kind of audible side effects with a program. Already back in the days when I started programming, I always played around with audio when toying around with a new language. I have found a wonderful set of lecture slides about haskell and multimedia programming, called school of expression. Inspired by the slides about functional music I implemented a little song. Ahh ... and yes it is intended to sound slightly strange . I used the synthesis toolkit to transform the music to real noise, simply by piping skini message to std-out. I used this command line to achieve the results audible in the table: sven@hhi1214a:~/Mukke$ ghc -o test1 test1.hs && ./test1 | stk-demo Plucked -n 16 -or -ip Sound samples: Plucked play Clarinet play Whistle(attention very crazy!) play As always the source... stueck = anfang :+: mitte :+: ende anfang = groovy :+: (Trans ...

Haskell Thread Ring Benchmark

Not as fast as the erlang version coming soon: import Control.Monad import Control.Concurrent import System.Environment import System.CPUTime fork_ring_elem prev_mvar _ = do next_mvar forkIO (ring_elem prev_mvar next_mvar) return next_mvar ring_elem :: MVar Int -> MVar Int -> IO () ring_elem prev_mv next_mv = run where run = do token putMVar next_mv (token - 1) when ( token > 0 ) run first_ring_elem :: MVar Int -> MVar Int -> IO () first_ring_elem prev_mv next_mv = run where run = do token putMVar next_mv (token - 1) putStrLn "." when ( token > 0 ) run main = do (procsArg:roundsArg:_) first_mvar t1 last_mvar t2 putStrLn ("forked processes in " ++ (show (t2 - t1)) ++ " ps") first_ring_elem last_mvar first_mvar t3 putStrLn "\n***finished***" putStrLn ("total time: " ++ (show (t3 - t1)) ++ " ps")

coping emacs #1

After having written a lot of erlang code with emacs(uhhm ... no, erlide, the erlang eclipse plugin, is not yet a viable alternative...), I decided to start (back-)porting eclipse features to emacs. Yeahhhh! I am now among those 1337 |-|4><025 that have their own ".emacs" in ~. Well one feature, that I can't live without, is moving the current line with Alt - up/down, this is really usefull together with another the other feature: duplicating the current line(Ctrl-Alt-up/down). Below is the elisp code that provides these features and binds them to the keys these are bound to in eclipse. Note: In contrast to the eclipse version of this feature, this implementation does not(yet) work with regions, but with lines only. Ok, put this in your ~/.emacs ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Written by Sven Heyll in 2008 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun sh-wind-col (thunk) (let ((...

Visualisation of DNA

After some attention has been caought by the wonderfull Rainbow DNA project, I have decided to join the club! Here is a very simplistic, far more useless way of visualising DNA: turtle graphics. I really cannot put up a website with comlete renderings of the DNA using turtle graphics, but I uploaded two sample images to my flikr account. I wanted to find out if turtle graphics could reveal diffrent sets of patterns as those perceivable with a color plot of basepairs. Attached is source code so you can see what the program does. You can also reuse the part that proceses the contents of "gbk" files containing genome data. The code is just a hack done at night while I was waiting in a starbucks for a friend to pick me up, so if you think this code is a mess - you earned your degree, I was just curios after I found out about the rainbow dna project. Well the idea of the program is very simple: 1. Initialise the turtle to be in center of the screen 2. read the next basepair, for ...

Boyer Moore Search Algorithm

I needed to find a String in a text file, so I wrote(rather hacked) a scheme imlementation of the boyer moore string search algoritm. This is just a hack. But it is commented. What do you think? (I decided to use this blog also as my cut-paste-source from now on.) ;; searches for string using boyer moore algorithm (define (>>boyer-moore needle haystack) (define needle-len (string-length needle)) (define hs-len (string-length haystack)) (define r-needle-list (reverse (string->list needle))) ;; two tables are build ;; compute the bad character shift table ;; it contains the number of chars to skip, if a character is encountered that is not the last of the search string. ;; (this table is only used after the search cursor was replaced) (define bad-char-shift-table (let loop ((shift 0) (nlist r-needle-list) (table '())) (if (eq? nlist '()) table (if (assv (car nlist) table) (loop (+ 1 shift) (c...

on the path to enlightenment...

My (and others who I infected) reaction to playing around with erlang, scheme and common lisp, was frustration. Not because these languages are bad, but because they are so nice and fun to programm with! One could even argue, that this alone results in reduced development time and better programms, but while this is definitely true, it hides the fact, that the afore mentioned languages increase efficiency of sw development also by technical means. To provide evidence for this hypothesis is out of the scope of this document, please look for yourself, there's plenty of good material about common lisp, scheme and erlang on the web, there are even life lisp coding videos on google video! I recently bought the new erlang book. It is great and I would recommend it without hesitation. There are also great books online that I started reading: htdp and sicp. Oh and not to forget to mention "little schemers" of wich the chapter about the Y-combinator is online ...(yeahh nice!) Now...

Blub Paradox

Ich habe da einen interessanten Artikel ueber das Blub Paradoxon gefunden. Jenes besagt, das fast alle Programmierer der These zustimmen, dass Programmiersprachen sich in ihrer "Macht" und Generalitaet unterscheiden, aber trotzdem nicht bereit sind einzusehen, das andere Programmierespachen besser sind als die, die sie habituell verwenden. Verdeutlicht wird das am Beispieln eines eingefleischten "Blub" Programmierers. "Blub" ist eine P.Sprache die im mittleren Bereich des Generalitaetskontinuums liegt, das sich zwischen Maschinencode an einem Ende - und Lisp am anderen Ende erstreckt. Der Blub Programmierer kennt alle Sprachen, die schwaecher als Blub sind, und fragt sich, wie man bloss ohne eine Feature "x" vernuenftig programmieren kann(- natuerlich verfuegt Blub ueber x). Ausserdem findet er, dass Blub alle Features hat die er braucht, und ihm erscheinen features in "hoeheren" Sprachen als verwirrend und unnoetig. Er denkt in Blub, u...

functional vs oo

well it's been a while and I have come to trivial but usefull conclusions lately. Once I thought functional programming was fundamentaly diffrent then oo style programming, but I actually realized how well many aspects of fp match to elements of oop; Functions are simply Objects, Closures are anonymous class, certain design patterns ressemble monads(decorator, chain of reponsibility,...) oo style programming can be seen as a restricted variation of functional programming. That matters because the key aspects of oop is encapsulation and information hiding. This can easyly be achieved in fp through the use of closures and the fact that functions can be treated like any other data. In oop very explicit notations usually exists, wich couple certain functions to certain data through the notion of objects. Both, to increase readability of complex programms, and to lighten the restrictions that come with encapsulation, an explicit notion of inheritance is used. While all this seems pretty...

Recent Comparison of jMock 1.1 and EasyMock 2.2

My Colleges and me are in the process of figureing out wich mock frameworks to use. One of my colleges has experiences with jMock and I have used diffrent versions of easymock. We wanted a detailed comparison to help us decide what the strengths and weaknesses are of the diffrent Mockframeworks. During a web search we discovered this comparison between jMock and Easymock. Although, regarding the authors background not necessarily, but to me most likely, this comparison of Jmock to an unspecified version of Easymock is biased towards jMock. Many diffrences/disadvantages in this comparison are obsoleted by more recent versions of Easymock, and speculating on the version used in favour of the author would imho result in 1.3 wich dates way back to 2005. The desription of the link to the jMock project on the easymock project page, states that jMock opposed to easymock uses another approach to define expectations that results in more flexibility to set expectations (you may specify almost e...

Future of Webdevelopment

The longterm future in Webdevelopment is for sure associated with fading boundaries between systems that provide a service wich incorporates distributed knowledge to form new knowledge, wich it distributes, probably only to one client in a secure fashion. These boundaries are hard boundaries in terms of possible incompatibilities between interacting systems in heterogenous environment. We are confronted with securtiy issues, incompatibilies in protocol interpretations and service metadata propagation for automatic wiring of resources as opposed to hand crafted wiring as i.e. done with hyperlinks between dynamic system with a proprietary but similar structure, we are confronted wich diffrences on many layers of abstraction and orthogonal technical aspects like the necessesity to transform data not only to diffrent semiotic representationens but also to devices with diffrent availibility and diffrent means of human interaction. As diversity greatly increases, the call for unification and...

Back again

After a lot of meditation over efficient programming styles, some new ideas finally condensed in my defected mind: always underestimated is the emotional aspect of coding, in a team environment one must be able to critisize and be critizised; also bad code pisses me of so much, that it pulls down my overall productivity test driven development saves time, most of the time clear structure and good documentation helps, because maintainance will be nicer (see 1.) usefull integration testing is a far away dream, never to be reached in a pure XP manner including acceptance tests. jira is cool - combined with good ole paper on the wall does best. customer requests - the customer(or any other person not a freak) will not put sufficient details for a bug or a feature request into the bugtracker or be helplessly faced with a complex and flexible task of specifeing an issue, here improvements to the GUI to reduce complexity by providing more project specific defaults would be nice) wikis are use...

Open and closed Source voting

In several countries voices are raised against the use of voting computers. The latest objection was raised by the CCC in germany. According to security analysis, voting machines are insecure, and allow for untracable manipulation of voting results and voter privacy. The software can be exchanged and votes could be manipulated without any traces. The systems used for voting in Germany are very similar to those in the Nederlands. Similar objects were raised before in this country. Andy Müller Maguhn wrote: Die Bauartzulassung der Nedap-Wahlcomputer ist nach den nunmehr vorliegenden Forschungsresultaten hinfällig. Das Bundesinnenministerium muss daher die Zulassung entsprechend § 3 Absatz 3 der Bundeswahlgeräteverordnung widerrufen It does not surprise that similar story are percepted in the USA, where some rumour around the company "Diebold Election Systems" raised, after a group of college students found some memos about the poor security of the system from developers of this...

Java Locking

Here are some nice Articles about Double checked locking, the singleton pattern and the friendly comepetition between people doing VM level locking (aka Synchronized) and Java locking (1.5 Reentrant locks) Double Checked Locking 1 Double Checked Locking 2 Why is ReentrantLock faster than synchronized ?

AntiPattern: AbstractionInversion

After trying to understand the AbstractionInversion antipattern, I wonder if this pattern is really a unique pattern and not actually more like a combination of other, more abstract AntiPatterns. Is AbstractionInversion a special case of code duplication, where a dependend class not only duplicates effort, but also escapes its level in a stack of abstracness layers inside an application? It seems to be common to most examples I have read so far, that AbstractionInversion occurs in conjunction with code/concept duplication in two dependent modules with diffrent levels of abstraction. To explain my thought I will rely on the ADA RendezVous example mentioned here. If i.e. a mutex is implemented by using the RendezVous concept, a mutex concept is actually implemented by using something at least as complex as a mutex, and code is likely duplicated. Furthermore the one-class-one responsibility rule seems violated in the above example, as the abstraction to the gory details of the model re...