Skip to content

Instantly share code, notes, and snippets.

@qertoip
Created August 1, 2010 06:04
Show Gist options
  • Select an option

  • Save qertoip/503008 to your computer and use it in GitHub Desktop.

Select an option

Save qertoip/503008 to your computer and use it in GitHub Desktop.

Revisions

  1. qertoip revised this gist Aug 21, 2010. 1 changed file with 11 additions and 2 deletions.
    13 changes: 11 additions & 2 deletions idiomatyczny_import.clj
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,13 @@
    ; Można w ten sposób zaimportować *.clj lub *.class wymienione z nazwy,
    ; Definicja przestrzeni nazw z importem funkcji Clojura i klas Javy

    (ns qertoip
    (:use
    [clojure.contrib.io :only [to-byte-array]]
    [clojure.contrib.java-utils :only [as-file]])
    (:import
    [java.io File FileOutputStream]))

    ; W poniższy sposób można zaimportować *.clj lub *.class wymienione z nazwy,
    ; znajdujące się w CLASSPATH. Nie można zaimportować całego pakietu.

    (use '[lib-name :only (var-names+)])
    (use '[lib-name :only (var-names+)])
  2. qertoip revised this gist Aug 1, 2010. 1 changed file with 5 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions repl_load_file.clj
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    ; Jak wczytać plik clj do REPL-a? Jeśli nie ma przestrzeni nazw,
    ; wystarczy load lub load-file

    (load-file "./temp.clj") ; z zadanej ścieżki
    (load "temp") ; z CLASSPATH
  3. qertoip revised this gist Aug 1, 2010. 1 changed file with 5 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions obiekty_javy.clj
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    ; Jak utworzyć obiekt Javy?

    (new Thread
    (fn [] ())
    )
  4. qertoip revised this gist Aug 1, 2010. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions metody_javy.clj
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    ; Jak wołać metody obiektu?

    (.metodaObiektu obiekt)
  5. qertoip revised this gist Aug 1, 2010. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion threadsafe_mutable_state.clj
    Original file line number Diff line number Diff line change
    @@ -6,6 +6,6 @@

    (dosync ; force transaction
    (alter accounts conj
    (struct 1 139.78)
    (struct account 1 139.78)
    )
    )
  6. qertoip revised this gist Aug 1, 2010. 1 changed file with 11 additions and 0 deletions.
    11 changes: 11 additions & 0 deletions threadsafe_mutable_state.clj
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    (defstruct account :id :balance)

    (def accounts
    (ref #{})
    )

    (dosync ; force transaction
    (alter accounts conj
    (struct 1 139.78)
    )
    )
  7. qertoip revised this gist Aug 1, 2010. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion odpowiednik_klasy.clj
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,8 @@
    ; W clojure nie ma klas znanych z programowania obiektowego.
    ; Najbliższym odpowiednikiem jest struktura z polami, coś jak struct w C.

    (defstruct person :first-name :last-name)
    (defstruct person :first-name :last-name)

    (struct person "Piotr" "Wlodarek")
    ; lub
    (struct-map person :first-name "Piotr", :last-name "Wlodarek")
  8. qertoip revised this gist Aug 1, 2010. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions list_comprehension.clj
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,4 @@
    ; odpowiednik w ruby:
    ; compositions.select{|c| c.name == "Requiem" }.map( &:composer )

    (for [c compositions :when (= "Requiem" (:name c))] (:composer c))
  9. qertoip revised this gist Aug 1, 2010. 4 changed files with 14 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions idiomatyczny_import.clj
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,4 @@
    ; Można w ten sposób zaimportować *.clj lub *.class wymienione z nazwy,
    ; znajdujące się w CLASSPATH. Nie można zaimportować całego pakietu.

    (use '[lib-name :only (var-names+)])
    4 changes: 4 additions & 0 deletions odpowiednik_klasy.clj
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,4 @@
    ; W clojure nie ma klas znanych z programowania obiektowego.
    ; Najbliższym odpowiednikiem jest struktura z polami, coś jak struct w C.

    (defstruct person :first-name :last-name)
    3 changes: 3 additions & 0 deletions statyczne_metody_javy.clj
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    ; Jak idiomatycznie wołać statyczne metody Javy?

    (Character/isWhitespace 32)
    3 changes: 3 additions & 0 deletions string_join.clj
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    (use '[clojure.contrib.str-utils :only (str-join)])

    (str-join "-" ["ala" "ma" "kota"])
  10. qertoip revised this gist Aug 1, 2010. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions odpowiednik_switch_case.clj
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,4 @@
    ; odpowiednik_switch_case.clj
    ; cond to macro, zwróci nil jeśli żaden z warunków nie był spełniony

    (cond
  11. qertoip revised this gist Aug 1, 2010. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion odpowiednik_switch_case.clj
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    ' cond to makro; zwróci nil jeśli żaden z warunków nie był spełniony
    ; cond to macro, zwróci nil jeśli żaden z warunków nie był spełniony

    (cond
    (< x 10) "less"
  12. qertoip created this gist Aug 1, 2010.
    6 changes: 6 additions & 0 deletions odpowiednik_switch_case.clj
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    ' cond to makro; zwróci nil jeśli żaden z warunków nie był spełniony

    (cond
    (< x 10) "less"
    (> x 10) "more"
    )