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
class String | |
def ngram(n) | |
characters = self.each_char.to_a | |
return [self] if characters.size <= n | |
return characters.each_cons(n).map(&:join) | |
end | |
end |
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
;;;; Gauche process | |
(use gauche.process) | |
(run-process '(notepad) :wait #t) | |
(let1 process (run-process '(notepad)) | |
; ...do some other work ... | |
(process-wait process)) |
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
;;;; Gauche hello | |
(print "Hello, Gauche!!!") | |
(format #t "Hello, ~s!~s\n" 'Gauche '!!) | |
(print (format #f "Hello, ~s!~s\n" 'Gauche '!!)) | |
(display "Hello, Gauche!!!\n") | |
(write "Hello, Gauche!!!") |
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
;;;; Gauche Closure | |
(define make_person | |
(lambda (name) | |
(lambda (say) | |
(print name ": " say)))) | |
(define (make_person2 name) ; syntax sugar | |
(lambda (say) | |
(print name ": " say))) |
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
;;;; Gauche Arguments | |
(define (main args) | |
(print args) | |
(print (car args)) ; SRFI22 | |
(print *program-name*) ; Gauche | |
) | |
; (args.scm foo bar) | |
; args.scm | |
; args.scm |
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 | |
# vim: fileencoding=utf-8 | |
require 'open-uri' | |
module NicoVideo | |
GETTHUMBINFO_URL = "http://ext.nicovideo.jp/api/getthumbinfo" | |
OK_STRING = %q|<nicovideo_thumb_response status="ok">| | |
FAIL_STRING = %q|<nicovideo_thumb_response status="fail">| | |
ELEMENTS = [:title, | |
:description, |
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
(use rfc.http) | |
(use rfc.uri) | |
(define-constant *getthumbinfo-url* "http://ext.nicovideo.jp/api/getthumbinfo") | |
(define-constant *ok-string* "<nicovideo_thumb_response status=\"ok\">") | |
(define-constant *fail-string* "<nicovideo_thumb_response status=\"fail\">") | |
(define-constant *elements* '(title description thumbnail_url watch_url)) | |
(define (getthumbinfo video-id) | |
(receive (code status body) |
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
(use rfc.http) | |
(use rfc.uri) | |
(define (uri-get uri) | |
(receive (code status body) | |
(receive (scheme user-info hostname port path query frament) | |
(uri-parse uri) | |
(if (eq? path #f) | |
(http-get hostname "/") | |
(http-get hostname path))) |
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
(equal? (list 1 2 3) (list 1 2 3)) ; => #t | |
((lambda (p) (eq? p p)) (cons 1 2)) ; => #t | |
(eq? 'example 'example) ; => #t | |
(eqv? 1 1) ; => #t | |
(eqv? 1 1.0) ; => #f | |
(= 1 1.0) ; => #t | |
(char=? #\a #\a) ; => #t | |
(string=? "example" "example") ; => #t | |
(char-ci=? #\a #\A) ; => #t | |
(string-ci=? "example" "EXAMPLE") ; => #t |
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
(pair? '(1)) ; => #t | |
(null? '()) ; => #t | |
(list? (list)) ; => #t | |
(boolean? #f) ; => #t | |
(symbol? 'example) ; => #t | |
(number? 1) ; => #t | |
(char? #\a) ; => #t | |
(string? "string") ; => #t | |
(odd? 1) ; => #t | |
(even? 2) ; => #t |
OlderNewer