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
| # Copyright 2012 Erlware, LLC. All Rights Reserved. | |
| # | |
| # This file is provided to you under the Apache License, | |
| # Version 2.0 (the "License"); you may not use this file | |
| # except in compliance with the License. You may obtain | |
| # a copy of the License at | |
| # | |
| # http://www.apache.org/licenses/LICENSE-2.0 | |
| # | |
| # Unless required by applicable law or agreed to in writing, |
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
| from pyswip import Prolog | |
| p = Prolog() | |
| # something is fun if it is a car and it is red. | |
| p.assertz('(fun(X) :- red(X), car(X))') | |
| # facts... | |
| p.assertz('car(vw_beatle)') | |
| p.assertz('car(ferrari)') | |
| p.assertz('car(hyundai)') |
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_module(library('clp/bounds')). | |
| sendmore(Digits) :- | |
| Digits = [S,E,N,D,M,O,R,Y], | |
| Digits in 0..9, | |
| S #\= 0, | |
| M #\= 0, | |
| all_different(Digits), | |
| 1000*S + 100*E + 10*N + D | |
| + 1000*M + 100*O + 10*R + E |
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
| 99 ^beers | |
| { | |
| %beers 0 > | |
| iftrue | |
| " bottle(s) of beer" & dup " on the wall," & println | |
| "." & println | |
| "Take one down, pass it around," println | |
| %beers -- ^beers | |
| repeat | |
| } |
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
| :bottles dup dup 1 > [" bottles"] [" bottle"] ifte cat ; | |
| :sing | |
| bottles dup " of beer on the wall," cat println | |
| " of beer. " cat println | |
| "Take one down, pass it around." println ; | |
| :theend "No more beer left." println ; | |
| :beers [dup 0 >] [sing decr] while theend eat ; |
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
| import pydcop | |
| playerService = pydcop.DCOPObject('amarok', 'player') | |
| d = dict( | |
| title=playerService.title(), | |
| artist=playerService.artist(), | |
| album=playerService.album() | |
| ) | |
| print '%(artist)s - %(title)s (%(album)s)' % d |
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
| def allstrings(alphabet, length): | |
| """Find the list of all strings of 'alphabet' of length 'length'""" | |
| if length == 0: return [] | |
| c = [[a] for a in alphabet[:]] | |
| if length == 1: return c | |
| c = [[x,y] for x in alphabet for y in alphabet] | |
| if length == 2: return c |
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
| package main | |
| import "fmt" | |
| import "http" | |
| import "os" | |
| import "bytes" | |
| import "regexp" | |
| import "strings" | |
| import "container/vector" | |
| import "flag" |
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
| # infix.mar | Converts an infix expression into postfix | |
| # This implementation uses the global variable space as a hash-table | |
| # for operator precedence. | |
| "listop forth dequeop" use | |
| @|> globs & pushfrom ; | |
| @string dfront NONE = |
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
| # infixoop.mar | Converts an infix expression into postfix | |
| # This implementation uses the object data as a hash-table | |
| # for operator precedence. | |
| "listop forth dequeop" use | |
| @@Infix | |
| @new # define the hash-table for operator precedence | |
| FALSE ^++ ^+- ^-+ ^-- ^*+ ^*- ^** ^*/ ^/+ ^/- ^/* :// |
OlderNewer