Beyond Mindless
вторник, 21 июня 2011 г.
пятница, 27 мая 2011 г.
LISP(SBCL) & MySQL. First spiritual experience
Next step of my journey into Lisp. I tried to create soft for myself, which I can use every day. Time to time I needed to read more and more manuals. And it gave results. Experience in the use of many structures Lisp comes with repeated usage. The "Praсtiсal Common Lisp" has become my desktop book. Many useful features are already implemented in this book have been used, and gave the key to understanding how to create these.
And one time, I tried to create function that use the standart unix terminal.
So I list some forums and found out that SBCL have functions for communicating with MySQL. Its call "cl-mysql". It is the system for working with databases.
For using this, you need to install the "cl-mysql", for example through Quicklisp.
Lets proceed from the fact that you already have Quicklisp. Next you install the system:
(quicklisp-quickstart:install)
(ql:quickload "cl-mysql")
Now you can test the SQL functions in REPL:
(cl-mysql:connect :host "localhost" :database "dbname" :user "root" :password "password")
(cl-mysql:query "select * from table")
For using this possibilities in action, I found only one way.
(ql:quickload "cl-mysql")
(defun test ()
(cl-mysql:connect
:host "localhost"
:database "db"
:user "root"
:password "password")
(cl-mysql:query "select * from test"))
Thats all for MySQL + SBCL, for this time.
Lets source be with you.
And one time, I tried to create function that use the standart unix terminal.
So I list some forums and found out that SBCL have functions for communicating with MySQL. Its call "cl-mysql". It is the system for working with databases.
For using this, you need to install the "cl-mysql", for example through Quicklisp.
Lets proceed from the fact that you already have Quicklisp. Next you install the system:
(quicklisp-quickstart:install)
(ql:quickload "cl-mysql")
Now you can test the SQL functions in REPL:
(cl-mysql:connect :host "localhost" :database "dbname" :user "root" :password "password")
(cl-mysql:query "select * from table")
For using this possibilities in action, I found only one way.
(ql:quickload "cl-mysql")
(defun test ()
(cl-mysql:connect
:host "localhost"
:database "db"
:user "root"
:password "password")
(cl-mysql:query "select * from test"))
Thats all for MySQL + SBCL, for this time.
Lets source be with you.
вторник, 25 января 2011 г.
My Emacs = SBCL + SLIME, and other voodoo
First of all at the beginning of my way I was faced with the choise of development environment. In LISP as well as in Haskell. When I started to work with LISP, I tried some environments in Windows (CLISP) and the same environment in UNiX OS, Ubuntu 10.10. After the certain time I decided that its not enough for work. 'Cause it have no relation between text editor and directly CLISP. Its very inconvenient. So I began to search for something more comfortable. And I found the Thing, call Emacs. After reviewing several forum on this topic, I found out that Emacs its the Great Devil's Plan. It is very difficult and multyform, 'cause you can create you own built of emacs, and configure files it's the private treasure of each developer. But Emacs - only text editor (yes, it was great simplification), and I need the CLISP module or something like that. Surfing the Internet, I found pack: Emacs + SLIME + SBCL. What is it. Step by step:
- Emacs - text-editor and the base of all other modules;
- Slime - Superior Lisp Interaction Mode for Emacs. Lisp in propia persona.
- SBCL - Steel Bank Common Lisp. Common Lisp compiler.
Sooooo. I found that I want. Lets install it! I will decribe the installation's steps of this software in Ubuntu 10.10.
Step1: Installing aptitude package. Open terminal and type:
Wait while it download and install.
Step2: Installing Emacs, SLIME and SBCL. Terminal, type:
Wait. Voila. It has installed.
Step3: Configure your Emacs.(NOTICE. This configuration is not mine. But I tested it)
Running Emacs. Open Emacs configuration file - press C-x C-f (if you have no the .emacs file, it will be create. It is normal). And copy this configuration to this file:
Now you have working copy of Emacs and you can use the SLIME-mode, as well.
Next step - configure Emacs for you. Add to .emacs file:
And the last part of configuration - color settings of text, commands, etc. Add:
Thats all. Use your Emacs and be happy.
- Emacs - text-editor and the base of all other modules;
- Slime - Superior Lisp Interaction Mode for Emacs. Lisp in propia persona.
- SBCL - Steel Bank Common Lisp. Common Lisp compiler.
Sooooo. I found that I want. Lets install it! I will decribe the installation's steps of this software in Ubuntu 10.10.
Step1: Installing aptitude package. Open terminal and type:
sudo apt-get install aptitude
Wait while it download and install.
Step2: Installing Emacs, SLIME and SBCL. Terminal, type:
sudo aptitude install -y emacs slime cl-asdf sbcl
Wait. Voila. It has installed.
Step3: Configure your Emacs.(NOTICE. This configuration is not mine. But I tested it)
Running Emacs. Open Emacs configuration file - press C-x C-f (if you have no the .emacs file, it will be create. It is normal). And copy this configuration to this file:
;; Set up the Common Lisp environment
(add-to-list 'load-path "/usr/share/common-lisp/source/slime/")
(setq inferior-lisp-program "/usr/bin/sbcl")
(require 'slime)
(slime-setup)
Now you have working copy of Emacs and you can use the SLIME-mode, as well.
Next step - configure Emacs for you. Add to .emacs file:
;; Text and the such
;; Use colors to highlight commands, etc.
(global-font-lock-mode t)
;; Disable the welcome message
(setq inhibit-startup-message t)
;; Format the title-bar to always include the buffer name
(setq frame-title-format "emacs - %b")
;; Display time
(display-time)
;; Make the mouse wheel scroll Emacs
(mouse-wheel-mode t)
;; Always end a file with a newline
(setq require-final-newline t)
;; Stop emacs from arbitrarily adding lines to the end of a file when the
;; cursor is moved past the end of it:
(setq next-line-add-newlines nil)
;; Flash instead of that annoying bell
(setq visible-bell t)
;; Remove icons toolbar
(if (> emacs-major-version 20)
(tool-bar-mode -1))
;; Use y or n instead of yes or not
(fset 'yes-or-no-p 'y-or-n-p)
And the last part of configuration - color settings of text, commands, etc. Add:
(defun faces_x ()
;; these are used when in X
(custom-set-faces
'(default ((t (:foreground "wheat" :background "black"))))
'(flyspell-duplicate ((t (:foreground "Gold3" :underline t :weight normal))))
'(flyspell-incorrect ((t (:foreground "OrangeRed" :underline t :weight normal))))
'(font-lock-comment-face ((t (:foreground "SteelBlue1"))))
'(font-lock-function-name-face ((t (:foreground "gold"))))
'(font-lock-keyword-face ((t (:foreground "springgreen"))))
'(font-lock-type-face ((t (:foreground "PaleGreen"))))
'(font-lock-variable-name-face ((t (:foreground "Coral"))))
'(menu ((((type x-toolkit)) (:background "light slate gray" :foreground "wheat" :box (:line-width 2 :color "grey75" :style released-button)))))
'(mode-line ((t (:foreground "black" :background "light slate gray"))))
'(tool-bar ((((type x w32 mac) (class color)) (:background "midnight blue" :foreground "wheat" :box (:line-width 1 :style released-button))))))
(set-cursor-color "deep sky blue")
(set-foreground-color "wheat")
(set-background-color "black")
(set-face-foreground 'default "wheat")
(set-face-background 'default "black"))
(defun faces_nox ()
;; these are used when in terminal
(custom-set-faces
'(default ((t (:foreground "white" :background "black"))))
'(font-lock-comment-face ((t (:foreground "magenta"))))
'(font-lock-function-name-face ((t (:foreground "red"))))
'(font-lock-keyword-face ((t (:foreground "green"))))
'(font-lock-type-face ((t (:foreground "blue"))))
'(font-lock-string-face ((t (:foreground "cyan"))))
'(font-lock-variable-name-face ((t (:foreground "blue"))))
'(menu ((((type x-toolkit)) (:background "white" :foreground "black" :box (:line-width 2 :color "grey75" :style released-button)))))
'(modeline ((t (:foreground "blue" :background "white")))))
(set-cursor-color "blue")
(set-foreground-color "white")
(set-background-color "black")
(set-face-foreground 'default "white")
(set-face-background 'default "black"))
(if window-system
(faces_x)
(faces_nox))
Thats all. Use your Emacs and be happy.
четверг, 20 января 2011 г.
Abracadabra in my mind. Part2
The second story with functional programming - it's my familiarity with scientific language Haskell. He is no more and no less mystical than LISP. The most common myth - Haskell created to study the properties of Haskell.
In the last century - yes, perhaps. But today, Haskell is a powerful tool for software development. Yes, he is a bit nonstandard, for people accustomed to the imperative style. But he has one undeniable advantage - he is very strong in the calculations, and it is truly an aesthetic code.
I'll make a formal presetation. Haskell it is a polymorphically statically typed, lazy, purely functional language, quite different from most other programming languages. The language is named for Haskell Brooks Curry, whose work in mathematical logic serves as a foundation for functional languages. [link]
Materials for the study of this language is sufficient if a good search. Russian-speaking is the fundamental book of the author Dushkin. However, in my opinion in many respects an explanation in this book was much too confusing and complicated. But to study just syntactic core, this book is good. Just for learning the basics, I found a very popular book - Learn you haskell for Great Good. But it is in English. Although it is much better to pick up the material and style of its presentation.
Again, to test their new knowledge in a "battle", I turned to freelancing. A familiar pattern - Odesk -> Project -> employer -> contract -> completed the project - got money.
The familiar feeling that I chopped nuts with microscope. Understanding that I'm not understand everything in the language. And once again return to the folio, and again to study, but more detailed and thorough. With the retreat to the books with the necessary additional information.
In future posts, I will report "progress" in learning the two languages that are interesting to me at the moment, apart from the language of algebraic rewriting, with whom I have associated dissertation.
In the last century - yes, perhaps. But today, Haskell is a powerful tool for software development. Yes, he is a bit nonstandard, for people accustomed to the imperative style. But he has one undeniable advantage - he is very strong in the calculations, and it is truly an aesthetic code.
I'll make a formal presetation. Haskell it is a polymorphically statically typed, lazy, purely functional language, quite different from most other programming languages. The language is named for Haskell Brooks Curry, whose work in mathematical logic serves as a foundation for functional languages. [link]
Materials for the study of this language is sufficient if a good search. Russian-speaking is the fundamental book of the author Dushkin. However, in my opinion in many respects an explanation in this book was much too confusing and complicated. But to study just syntactic core, this book is good. Just for learning the basics, I found a very popular book - Learn you haskell for Great Good. But it is in English. Although it is much better to pick up the material and style of its presentation.
Again, to test their new knowledge in a "battle", I turned to freelancing. A familiar pattern - Odesk -> Project -> employer -> contract -> completed the project - got money.
The familiar feeling that I chopped nuts with microscope. Understanding that I'm not understand everything in the language. And once again return to the folio, and again to study, but more detailed and thorough. With the retreat to the books with the necessary additional information.
In future posts, I will report "progress" in learning the two languages that are interesting to me at the moment, apart from the language of algebraic rewriting, with whom I have associated dissertation.
вторник, 18 января 2011 г.
Abracadabra in my mind
Ones apon a time I decided to find out about mystery programming language called - LISP. The number of myths surrounding this language surpasses all reasonable limits.
The most common myths that I have heard by myself:
Writing LISP programms before long years of uni life and learning at unversity imperative programming languages, like C#, Java, etc. - its something crazy.
So I started with the bases of the language. For example, not bad option for russian-language people is the course at the INTUIT, or the posts at Habrahabr. Of course we can take the book, aren't we? After some time of searching via global web, I found some interesting books about LISP. All collection of books you can find here. Its all russian-language, except the SICP.
Some time studying on courses INTUIT and some books, I decided to test the knowledge in action. Where can I do it? FreeLance - of course. On the advice of a friend chose the site odesk.com. I found 2 project with the requirements of knowledge LISP. Not bad payment, and no competition. Great! I've got it. Because of the lack of PayPal or WebMoney account, I decided to contact to employer directly. Agreed on the timing of work and payment method, passing the site odesk, and 3 weeks later I passed the project and received payment.
After that, I realized that I did not know anything about LISP. I tried to wrote code in non-imperative manner, but I had not enough knowledges. So I went to study Lisp more closly. In the process of learning, I bumped into another functional language - Haskell. But its the topic of future posts.
The most common myths that I have heard by myself:
- Its the godlike language that can everything, and nothing couldn't be better that LISP.
- It can be usefull only at narrow scientific enviroment.
- Lisp is - Lots of Idiotic Silly Parentheses, and source-files of LISP in unreadable.
Writing LISP programms before long years of uni life and learning at unversity imperative programming languages, like C#, Java, etc. - its something crazy.
So I started with the bases of the language. For example, not bad option for russian-language people is the course at the INTUIT, or the posts at Habrahabr. Of course we can take the book, aren't we? After some time of searching via global web, I found some interesting books about LISP. All collection of books you can find here. Its all russian-language, except the SICP.
Some time studying on courses INTUIT and some books, I decided to test the knowledge in action. Where can I do it? FreeLance - of course. On the advice of a friend chose the site odesk.com. I found 2 project with the requirements of knowledge LISP. Not bad payment, and no competition. Great! I've got it. Because of the lack of PayPal or WebMoney account, I decided to contact to employer directly. Agreed on the timing of work and payment method, passing the site odesk, and 3 weeks later I passed the project and received payment.
After that, I realized that I did not know anything about LISP. I tried to wrote code in non-imperative manner, but I had not enough knowledges. So I went to study Lisp more closly. In the process of learning, I bumped into another functional language - Haskell. But its the topic of future posts.
Подписаться на:
Сообщения (Atom)