(dolist (var init-form result) S式 ... )
dolist は名前が示すように、リストに関係があります。最初に init-form を評価します。このとき、評価結果はリストでなければいけません。リスト以外の場合はエラーとなります。dolist は、このリストの要素を順番に変数 var に代入して S 式を評価します。リストの要素がなくなったら result を評価し、その値が dolist の返り値になります。次の例を見てください。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defmacro sum [bindings expr] | |
`(reduce + (for ~bindings ~expr))) | |
(macroexpand-1 '(sum [x '(1 2 3) | |
y '(4 5 6)] | |
(+ x y))) | |
(clojure.core/reduce | |
clojure.core/+ | |
(clojure.core/for [x (quote (1 2 3)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(require '[clojure.tools.cli :as cli]) | |
(defn- get-cli-opts [args] | |
(cli/cli args | |
["--file" "File name of training" :default "./filtered_docs/all.json"] | |
["--alpha" "Hyperparameter for domain dependent/independant prior" | |
:default 1.0 :parse-fn #(Double. %)] | |
["--beta" "Hyperparameter for word prior" | |
:default 0.01 :parse-fn #(Double. %)] | |
["--gamma" "Hyperparameter for sentiment prior" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
require "rubygems" | |
require "mechanize" | |
require "optparse" | |
require "hpricot" | |
require "text/hatena" | |
require "pp" | |
@options = { | |
:c => false, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /opt/local/bin/ruby | |
# -*- coding: utf-8 -*- | |
require 'open3' | |
error = "" | |
Open3.popen3("R --vanilla -q -e \"parse(file=\\\"#{ARGV[0]}\\\")\""){|stdin, stdout, stderr| | |
error = stderr.read.to_s | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# -*- coding: utf-8 -*- | |
require "optparse" | |
@options = { | |
:hatena => nil, #はてなで開く | |
} | |
opts = OptionParser.new |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/opt/local/bin/ruby1.9 | |
# -*- coding: utf-8 -*- | |
require 'hparser' | |
puts HParser::Parser.new.parse(STDIN.read).map {|e| e.to_html }.join("\n") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
class Entry | |
attr_accessor :name | |
def initialize(name) | |
@name = name | |
end | |
def display(indent=0) | |
end | |
def make |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /opt/local/bin/ruby1.9 | |
# -*- coding: utf-8 -*- | |
require 'mechanize' | |
require 'logger' | |
require 'time' | |
require 'optparse' | |
require 'pp' | |
class HatenaGroupKeyword | |
attr_accessor :agent |