mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 17:50:22 +00:00
Compare commits
35 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b8f3078966 | ||
|
|
d496aaae55 | ||
|
|
87e60cfd78 | ||
|
|
2077fa3837 | ||
|
|
95bedf0bfc | ||
|
|
3a1b17f1f9 | ||
|
|
bdec1ac64d | ||
|
|
36a0d760e9 | ||
|
|
a901e85c3c | ||
|
|
6e9dc2339d | ||
|
|
3864e712ef | ||
|
|
8376f1e4a4 | ||
|
|
1b0fd752d3 | ||
|
|
bef473a48b | ||
|
|
0c60078d27 | ||
|
|
2f65462ce0 | ||
|
|
ace6156c65 | ||
|
|
ada8feba34 | ||
|
|
75d685a7f4 | ||
|
|
6b7f20323b | ||
|
|
c2ab5bc09d | ||
|
|
95d5b8bdbc | ||
|
|
da7b3182e8 | ||
|
|
08790f2f0a | ||
|
|
896270e617 | ||
|
|
fb40ee986f | ||
|
|
20b82e4bc9 | ||
|
|
513347911e | ||
|
|
1a3960e95d | ||
|
|
7d9a47b7c3 | ||
|
|
c80d085e33 | ||
|
|
98518e5c8c | ||
|
|
ef9e1c4e4f | ||
|
|
cf483c28e3 | ||
|
|
a5b915d571 |
30
.gitmodules
vendored
30
.gitmodules
vendored
@@ -528,9 +528,6 @@
|
||||
[submodule "vendor/grammars/sublime-bsv"]
|
||||
path = vendor/grammars/sublime-bsv
|
||||
url = https://github.com/thotypous/sublime-bsv
|
||||
[submodule "vendor/grammars/AutoHotkey"]
|
||||
path = vendor/grammars/AutoHotkey
|
||||
url = https://github.com/robertcollier4/AutoHotkey
|
||||
[submodule "vendor/grammars/Sublime-HTTP"]
|
||||
path = vendor/grammars/Sublime-HTTP
|
||||
url = https://github.com/httpspec/sublime-highlighting
|
||||
@@ -555,3 +552,30 @@
|
||||
[submodule "vendor/grammars/liquid.tmbundle"]
|
||||
path = vendor/grammars/liquid.tmbundle
|
||||
url = https://github.com/bastilian/validcode-textmate-bundles
|
||||
[submodule "vendor/grammars/AutoHotkey"]
|
||||
path = vendor/grammars/AutoHotkey
|
||||
url = https://github.com/ahkscript/AutoHotkey
|
||||
[submodule "vendor/grammars/ats.sublime"]
|
||||
path = vendor/grammars/ats.sublime
|
||||
url = https://github.com/steinwaywhw/ats-mode-sublimetext
|
||||
[submodule "vendor/grammars/Modelica"]
|
||||
path = vendor/grammars/Modelica
|
||||
url = https://github.com/BorisChumichev/modelicaSublimeTextPackage
|
||||
[submodule "vendor/grammars/sublime-apl"]
|
||||
path = vendor/grammars/sublime-apl
|
||||
url = https://github.com/StoneCypher/sublime-apl
|
||||
[submodule "vendor/grammars/CLIPS-sublime"]
|
||||
path = vendor/grammars/CLIPS-sublime
|
||||
url = https://github.com/psicomante/CLIPS-sublime
|
||||
[submodule "vendor/grammars/Creole"]
|
||||
path = vendor/grammars/Creole
|
||||
url = https://github.com/Siddley/Creole
|
||||
[submodule "vendor/grammars/GDScript-sublime"]
|
||||
path = vendor/grammars/GDScript-sublime
|
||||
url = https://github.com/beefsack/GDScript-sublime
|
||||
[submodule "vendor/grammars/sublime-golo"]
|
||||
path = vendor/grammars/sublime-golo
|
||||
url = https://github.com/TypeUnsafe/sublime-golo
|
||||
[submodule "vendor/grammars/JSyntax"]
|
||||
path = vendor/grammars/JSyntax
|
||||
url = https://github.com/bcj/JSyntax
|
||||
|
||||
16
grammars.yml
16
grammars.yml
@@ -26,15 +26,21 @@ vendor/grammars/Alloy.tmbundle:
|
||||
- source.alloy
|
||||
vendor/grammars/AutoHotkey:
|
||||
- source.ahk
|
||||
vendor/grammars/CLIPS-sublime:
|
||||
- source.clips
|
||||
vendor/grammars/ColdFusion:
|
||||
- source.cfscript
|
||||
- source.cfscript.cfc
|
||||
- text.cfml.basic
|
||||
- text.html.cfm
|
||||
vendor/grammars/Creole:
|
||||
- text.html.creole
|
||||
vendor/grammars/Docker.tmbundle:
|
||||
- source.dockerfile
|
||||
vendor/grammars/Elm.tmLanguage:
|
||||
- source.elm
|
||||
vendor/grammars/GDScript-sublime/:
|
||||
- source.gdscript
|
||||
vendor/grammars/Handlebars:
|
||||
- text.html.handlebars
|
||||
vendor/grammars/IDL-Syntax:
|
||||
@@ -42,10 +48,14 @@ vendor/grammars/IDL-Syntax:
|
||||
vendor/grammars/Isabelle.tmbundle:
|
||||
- source.isabelle.root
|
||||
- source.isabelle.theory
|
||||
vendor/grammars/JSyntax/:
|
||||
- source.j
|
||||
vendor/grammars/Julia.tmbundle:
|
||||
- source.julia
|
||||
vendor/grammars/LiveScript.tmbundle:
|
||||
- source.livescript
|
||||
vendor/grammars/Modelica/:
|
||||
- source.modelica
|
||||
vendor/grammars/NSIS:
|
||||
- source.nsis
|
||||
vendor/grammars/NimLime:
|
||||
@@ -128,6 +138,8 @@ vendor/grammars/assembly.tmbundle:
|
||||
vendor/grammars/atom-salt:
|
||||
- source.python.salt
|
||||
- source.yaml.salt
|
||||
vendor/grammars/ats.sublime:
|
||||
- source.ats
|
||||
vendor/grammars/autoitv3-tmbundle:
|
||||
- source.autoit.3
|
||||
vendor/grammars/awk-sublime:
|
||||
@@ -404,6 +416,8 @@ vendor/grammars/standard-ml.tmbundle:
|
||||
- source.ml
|
||||
vendor/grammars/sublime-MuPAD:
|
||||
- source.mupad
|
||||
vendor/grammars/sublime-apl/:
|
||||
- source.apl
|
||||
vendor/grammars/sublime-befunge:
|
||||
- source.befunge
|
||||
vendor/grammars/sublime-better-typescript:
|
||||
@@ -415,6 +429,8 @@ vendor/grammars/sublime-cirru:
|
||||
vendor/grammars/sublime-glsl:
|
||||
- source.essl
|
||||
- source.glsl
|
||||
vendor/grammars/sublime-golo/:
|
||||
- source.golo
|
||||
vendor/grammars/sublime-idris:
|
||||
- source.idris
|
||||
vendor/grammars/sublime-mask:
|
||||
|
||||
@@ -54,7 +54,7 @@ APL:
|
||||
extensions:
|
||||
- .apl
|
||||
- .dyalog
|
||||
tm_scope: none
|
||||
tm_scope: source.apl
|
||||
ace_mode: text
|
||||
|
||||
ASP:
|
||||
@@ -82,10 +82,9 @@ ATS:
|
||||
- ats2
|
||||
extensions:
|
||||
- .dats
|
||||
- .atxt
|
||||
- .hats
|
||||
- .sats
|
||||
tm_scope: source.ocaml
|
||||
tm_scope: source.ats
|
||||
ace_mode: ocaml
|
||||
|
||||
ActionScript:
|
||||
@@ -382,6 +381,7 @@ C++:
|
||||
- .cpp
|
||||
- .c++
|
||||
- .cc
|
||||
- .cp
|
||||
- .cxx
|
||||
- .h
|
||||
- .h++
|
||||
@@ -414,7 +414,7 @@ CLIPS:
|
||||
type: programming
|
||||
extensions:
|
||||
- .clp
|
||||
tm_scope: none
|
||||
tm_scope: source.clips
|
||||
ace_mode: text
|
||||
|
||||
CMake:
|
||||
@@ -623,7 +623,7 @@ Creole:
|
||||
wrap: true
|
||||
extensions:
|
||||
- .creole
|
||||
tm_scope: none
|
||||
tm_scope: text.html.creole
|
||||
ace_mode: text
|
||||
|
||||
Crystal:
|
||||
@@ -918,6 +918,7 @@ Forth:
|
||||
color: "#341708"
|
||||
extensions:
|
||||
- .fth
|
||||
- .4TH
|
||||
- .4th
|
||||
- .F
|
||||
- .f
|
||||
@@ -976,7 +977,7 @@ GDScript:
|
||||
type: programming
|
||||
extensions:
|
||||
- .gd
|
||||
tm_scope: none
|
||||
tm_scope: source.gdscript
|
||||
ace_mode: text
|
||||
|
||||
GLSL:
|
||||
@@ -1074,7 +1075,7 @@ Golo:
|
||||
color: "#f6a51f"
|
||||
extensions:
|
||||
- .golo
|
||||
tm_scope: none
|
||||
tm_scope: source.golo
|
||||
ace_mode: text
|
||||
|
||||
Gosu:
|
||||
@@ -1240,6 +1241,7 @@ Handlebars:
|
||||
type: markup
|
||||
aliases:
|
||||
- hbs
|
||||
- htmlbars
|
||||
extensions:
|
||||
- .handlebars
|
||||
- .hbs
|
||||
@@ -1375,7 +1377,7 @@ J:
|
||||
type: programming
|
||||
extensions:
|
||||
- .ijs
|
||||
tm_scope: none
|
||||
tm_scope: source.j
|
||||
ace_mode: text
|
||||
|
||||
JSON:
|
||||
@@ -1839,6 +1841,13 @@ Mirah:
|
||||
tm_scope: source.ruby
|
||||
ace_mode: ruby
|
||||
|
||||
Modelica:
|
||||
type: programming
|
||||
extensions:
|
||||
- .mo
|
||||
tm_scope: source.modelica
|
||||
ace_mode: text
|
||||
|
||||
Monkey:
|
||||
type: programming
|
||||
extensions:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
module Linguist
|
||||
module Strategy
|
||||
class Modeline
|
||||
EmacsModeline = /-\*-\s*(?:mode:)?\s*(\w+);?\s*-\*-/
|
||||
EmacsModeline = /-\*-\s*mode:\s*(\w+);?\s*-\*-/
|
||||
VimModeline = /\/\*\s*vim:\s*set\s*(?:ft|filetype)=(\w+):\s*\*\//
|
||||
|
||||
# Public: Detects language based on Vim and Emacs modelines
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
module Linguist
|
||||
VERSION = "4.3.0"
|
||||
VERSION = "4.3.1"
|
||||
end
|
||||
|
||||
@@ -1,215 +0,0 @@
|
||||
%{
|
||||
#include "./../ATEXT/atextfun.hats"
|
||||
%}
|
||||
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
|
||||
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
|
||||
<head>
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
|
||||
<title>EFFECTIVATS-DiningPhil2</title>
|
||||
#patscode_style()
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<h1>
|
||||
Effective ATS: Dining Philosophers
|
||||
</h1>
|
||||
|
||||
In this article, I present an implementation of a slight variant of the
|
||||
famous problem of 5-Dining-Philosophers by Dijkstra that makes simple but
|
||||
convincing use of linear types.
|
||||
|
||||
<h2>
|
||||
The Original Problem
|
||||
</h2>
|
||||
|
||||
There are five philosophers sitting around a table and there are also 5
|
||||
forks placed on the table such that each fork is located between the left
|
||||
hand of a philosopher and the right hand of another philosopher. Each
|
||||
philosopher does the following routine repeatedly: thinking and dining. In
|
||||
order to dine, a philosopher needs to first acquire two forks: one located
|
||||
on his left-hand side and the other on his right-hand side. After
|
||||
finishing dining, a philosopher puts the two acquired forks onto the table:
|
||||
one on his left-hand side and the other on his right-hand side.
|
||||
|
||||
<h2>
|
||||
A Variant of the Original Problem
|
||||
</h2>
|
||||
|
||||
The following twist is added to the original version:
|
||||
|
||||
<p>
|
||||
|
||||
After a fork is used, it becomes a "dirty" fork and needs to be put in a
|
||||
tray for dirty forks. There is a cleaner who cleans dirty forks and then
|
||||
puts them back on the table.
|
||||
|
||||
<h2>
|
||||
Channels for Communication
|
||||
</h2>
|
||||
|
||||
A channel is just a shared queue of fixed capacity. The following two
|
||||
functions are for inserting an element into and taking an element out of a
|
||||
given channel:
|
||||
|
||||
<pre
|
||||
class="patsyntax">
|
||||
#pats2xhtml_sats("\
|
||||
fun{a:vt0p} channel_insert (channel (a), a): void
|
||||
fun{a:vt0p} channel_takeout (chan: channel (a)): (a)
|
||||
")</pre>
|
||||
|
||||
If [channel_insert] is called on a channel that is full, then the caller is
|
||||
blocked until an element is taken out of the channel. If [channel_takeout]
|
||||
is called on a channel that is empty, then the caller is blocked until an
|
||||
element is inserted into the channel.
|
||||
|
||||
<h2>
|
||||
A Channel for Each Fork
|
||||
</h2>
|
||||
|
||||
Forks are resources given a linear type. Each fork is initially stored in a
|
||||
channel, which can be obtained by calling the following function:
|
||||
|
||||
<pre
|
||||
class="patsyntax">
|
||||
#pats2xhtml_sats("\
|
||||
fun fork_changet (n: nphil): channel(fork)
|
||||
")</pre>
|
||||
|
||||
where the type [nphil] is defined to be [natLt(5)] (for natural numbers
|
||||
less than 5). The channels for storing forks are chosen to be of capacity
|
||||
2. The reason that channels of capacity 2 are chosen to store at most one
|
||||
element (in each of them) is to guarantee that these channels can never be
|
||||
full (so that there is no attempt made to send signals to awake callers
|
||||
supposedly being blocked due to channels being full).
|
||||
|
||||
|
||||
<h2>
|
||||
A Channel for the Fork Tray
|
||||
</h2>
|
||||
|
||||
A tray for storing "dirty" forks is also a channel, which can be obtained
|
||||
by calling the following function:
|
||||
|
||||
<pre
|
||||
class="patsyntax">
|
||||
#pats2xhtml_sats("\
|
||||
fun forktray_changet ((*void*)): channel(fork)
|
||||
")</pre>
|
||||
|
||||
The capacity chosen for the channel is 6 (instead of 5) so that it can
|
||||
never become full (as there are only 5 forks in total).
|
||||
|
||||
<h2>
|
||||
Philosopher Loop
|
||||
</h2>
|
||||
|
||||
Each philosopher is implemented as a loop:
|
||||
|
||||
<pre
|
||||
class="patsyntax">
|
||||
#pats2xhtml_dats('\
|
||||
implement
|
||||
phil_loop (n) = let
|
||||
//
|
||||
val () = phil_think (n)
|
||||
//
|
||||
val nl = phil_left (n) // = n
|
||||
val nr = phil_right (n) // = (n+1) % 5
|
||||
//
|
||||
val ch_lfork = fork_changet (nl)
|
||||
val ch_rfork = fork_changet (nr)
|
||||
//
|
||||
val lf = channel_takeout (ch_lfork)
|
||||
val () = println! ("phil_loop(", n, ") picks left fork")
|
||||
//
|
||||
val () = randsleep (2) // sleep up to 2 seconds
|
||||
//
|
||||
val rf = channel_takeout (ch_rfork)
|
||||
val () = println! ("phil_loop(", n, ") picks right fork")
|
||||
//
|
||||
val () = phil_dine (n, lf, rf)
|
||||
//
|
||||
val ch_forktray = forktray_changet ()
|
||||
val () = channel_insert (ch_forktray, lf) // left fork to dirty tray
|
||||
val () = channel_insert (ch_forktray, rf) // right fork to dirty tray
|
||||
//
|
||||
in
|
||||
phil_loop (n)
|
||||
end // end of [phil_loop]
|
||||
')</pre>
|
||||
|
||||
It should be straighforward to follow the code for [phil_loop].
|
||||
|
||||
<h2>
|
||||
Fork Cleaner Loop
|
||||
</h2>
|
||||
|
||||
A cleaner is implemented as a loop:
|
||||
|
||||
<pre
|
||||
class="patsyntax">
|
||||
#pats2xhtml_dats('\
|
||||
implement
|
||||
cleaner_loop () = let
|
||||
//
|
||||
val ch = forktray_changet ()
|
||||
val f0 = channel_takeout (ch) // [f0] is dirty
|
||||
//
|
||||
val () = cleaner_wash (f0) // washes dirty [f0]
|
||||
val () = cleaner_return (f0) // puts back cleaned [f0]
|
||||
//
|
||||
in
|
||||
cleaner_loop ()
|
||||
end // end of [cleaner_loop]
|
||||
')</pre>
|
||||
|
||||
The function [cleaner_return] first finds out the number of a given fork
|
||||
and then uses the number to locate the channel for storing the fork. Its
|
||||
actual implementation is given as follows:
|
||||
|
||||
<pre
|
||||
class="patsyntax">
|
||||
#pats2xhtml_dats('\
|
||||
implement
|
||||
cleaner_return (f) =
|
||||
{
|
||||
val n = fork_get_num (f)
|
||||
val ch = fork_changet (n)
|
||||
val () = channel_insert (ch, f)
|
||||
}
|
||||
')</pre>
|
||||
|
||||
It should now be straighforward to follow the code for [cleaner_loop].
|
||||
|
||||
<h2>
|
||||
Testing
|
||||
</h2>
|
||||
|
||||
The entire code of this implementation is stored in the following files:
|
||||
|
||||
<pre>
|
||||
DiningPhil2.sats
|
||||
DiningPhil2.dats
|
||||
DiningPhil2_fork.dats
|
||||
DiningPhil2_thread.dats
|
||||
</pre>
|
||||
|
||||
There is also a Makefile available for compiling the ATS source code into
|
||||
an excutable for testing. One should be able to encounter a deadlock after
|
||||
running the simulation for a while.
|
||||
|
||||
<hr size="2">
|
||||
|
||||
This article is written by <a href="http://www.cs.bu.edu/~hwxi/">Hongwei Xi</a>.
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
%{
|
||||
implement main () = fprint_filsub (stdout_ref, "main_atxt.txt")
|
||||
%}
|
||||
116
samples/C++/qsciprinter.cp
Normal file
116
samples/C++/qsciprinter.cp
Normal file
@@ -0,0 +1,116 @@
|
||||
// This module defines interface to the QsciPrinter class.
|
||||
//
|
||||
// Copyright (c) 2011 Riverbank Computing Limited <info@riverbankcomputing.com>
|
||||
//
|
||||
// This file is part of QScintilla.
|
||||
//
|
||||
// This file may be used under the terms of the GNU General Public
|
||||
// License versions 2.0 or 3.0 as published by the Free Software
|
||||
// Foundation and appearing in the files LICENSE.GPL2 and LICENSE.GPL3
|
||||
// included in the packaging of this file. Alternatively you may (at
|
||||
// your option) use any later version of the GNU General Public
|
||||
// License if such license has been publicly approved by Riverbank
|
||||
// Computing Limited (or its successors, if any) and the KDE Free Qt
|
||||
// Foundation. In addition, as a special exception, Riverbank gives you
|
||||
// certain additional rights. These rights are described in the Riverbank
|
||||
// GPL Exception version 1.1, which can be found in the file
|
||||
// GPL_EXCEPTION.txt in this package.
|
||||
//
|
||||
// If you are unsure which license is appropriate for your use, please
|
||||
// contact the sales department at sales@riverbankcomputing.com.
|
||||
//
|
||||
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
||||
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
|
||||
#ifndef QSCIPRINTER_H
|
||||
#define QSCIPRINTER_H
|
||||
|
||||
#ifdef __APPLE__
|
||||
extern "C++" {
|
||||
#endif
|
||||
|
||||
#include <qprinter.h>
|
||||
|
||||
#include <Qsci/qsciglobal.h>
|
||||
#include <Qsci/qsciscintilla.h>
|
||||
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QRect;
|
||||
class QPainter;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
class QsciScintillaBase;
|
||||
|
||||
|
||||
//! \brief The QsciPrinter class is a sub-class of the Qt QPrinter class that
|
||||
//! is able to print the text of a Scintilla document.
|
||||
//!
|
||||
//! The class can be further sub-classed to alter to layout of the text, adding
|
||||
//! headers and footers for example.
|
||||
class QSCINTILLA_EXPORT QsciPrinter : public QPrinter
|
||||
{
|
||||
public:
|
||||
//! Constructs a printer paint device with mode \a mode.
|
||||
QsciPrinter(PrinterMode mode = ScreenResolution);
|
||||
|
||||
//! Destroys the QsciPrinter instance.
|
||||
virtual ~QsciPrinter();
|
||||
|
||||
//! Format a page, by adding headers and footers for example, before the
|
||||
//! document text is drawn on it. \a painter is the painter to be used to
|
||||
//! add customised text and graphics. \a drawing is true if the page is
|
||||
//! actually being drawn rather than being sized. \a painter drawing
|
||||
//! methods must only be called when \a drawing is true. \a area is the
|
||||
//! area of the page that will be used to draw the text. This should be
|
||||
//! modified if it is necessary to reserve space for any customised text or
|
||||
//! graphics. By default the area is relative to the printable area of the
|
||||
//! page. Use QPrinter::setFullPage() because calling printRange() if you
|
||||
//! want to try and print over the whole page. \a pagenr is the number of
|
||||
//! the page. The first page is numbered 1.
|
||||
virtual void formatPage(QPainter &painter, bool drawing, QRect &area,
|
||||
int pagenr);
|
||||
|
||||
//! Return the number of points to add to each font when printing.
|
||||
//!
|
||||
//! \sa setMagnification()
|
||||
int magnification() const {return mag;}
|
||||
|
||||
//! Sets the number of points to add to each font when printing to \a
|
||||
//! magnification.
|
||||
//!
|
||||
//! \sa magnification()
|
||||
virtual void setMagnification(int magnification);
|
||||
|
||||
//! Print a range of lines from the Scintilla instance \a qsb. \a from is
|
||||
//! the first line to print and a negative value signifies the first line
|
||||
//! of text. \a to is the last line to print and a negative value
|
||||
//! signifies the last line of text. true is returned if there was no
|
||||
//! error.
|
||||
virtual int printRange(QsciScintillaBase *qsb, int from = -1, int to = -1);
|
||||
|
||||
//! Return the line wrap mode used when printing. The default is
|
||||
//! QsciScintilla::WrapWord.
|
||||
//!
|
||||
//! \sa setWrapMode()
|
||||
QsciScintilla::WrapMode wrapMode() const {return wrap;}
|
||||
|
||||
//! Sets the line wrap mode used when printing to \a wmode.
|
||||
//!
|
||||
//! \sa wrapMode()
|
||||
virtual void setWrapMode(QsciScintilla::WrapMode wmode);
|
||||
|
||||
private:
|
||||
int mag;
|
||||
QsciScintilla::WrapMode wrap;
|
||||
|
||||
QsciPrinter(const QsciPrinter &);
|
||||
QsciPrinter &operator=(const QsciPrinter &);
|
||||
};
|
||||
|
||||
#ifdef __APPLE__
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
343
samples/CLIPS/demo.clp
Normal file
343
samples/CLIPS/demo.clp
Normal file
@@ -0,0 +1,343 @@
|
||||
;;;***************************
|
||||
;;;* DEFFACTS KNOWLEDGE BASE *
|
||||
;;;***************************
|
||||
|
||||
(deffacts MAIN::knowledge-base
|
||||
(welcome (message WelcomeMessage))
|
||||
(goal (variable type.animal))
|
||||
(legalanswers (values yes no))
|
||||
(displayanswers (values "Yes" "No"))
|
||||
(rule (if backbone is yes)
|
||||
(then superphylum is backbone))
|
||||
(rule (if backbone is no)
|
||||
(then superphylum is jellyback))
|
||||
(question (variable backbone)
|
||||
(query backbone.query))
|
||||
(rule (if superphylum is backbone and
|
||||
warm.blooded is yes)
|
||||
(then phylum is warm))
|
||||
(rule (if superphylum is backbone and
|
||||
warm.blooded is no)
|
||||
(then phylum is cold))
|
||||
(question (variable warm.blooded)
|
||||
(query warm.blooded.query))
|
||||
(rule (if superphylum is jellyback and
|
||||
live.prime.in.soil is yes)
|
||||
(then phylum is soil))
|
||||
(rule (if superphylum is jellyback and
|
||||
live.prime.in.soil is no)
|
||||
(then phylum is elsewhere))
|
||||
(question (variable live.prime.in.soil)
|
||||
(query live.prime.in.soil.query))
|
||||
(rule (if phylum is warm and
|
||||
has.breasts is yes)
|
||||
(then class is breasts))
|
||||
(rule (if phylum is warm and
|
||||
has.breasts is no)
|
||||
(then type.animal is bird))
|
||||
(question (variable has.breasts)
|
||||
(query has.breasts.query))
|
||||
(rule (if phylum is cold and
|
||||
always.in.water is yes)
|
||||
(then class is water))
|
||||
(rule (if phylum is cold and
|
||||
always.in.water is no)
|
||||
(then class is dry))
|
||||
(question (variable always.in.water)
|
||||
(query always.in.water.query))
|
||||
(rule (if phylum is soil and
|
||||
flat.bodied is yes)
|
||||
(then type.animal is flatworm))
|
||||
(rule (if phylum is soil and
|
||||
flat.bodied is no)
|
||||
(then type.animal is worm.leech))
|
||||
(question (variable flat.bodied)
|
||||
(query flat.bodied.query))
|
||||
(rule (if phylum is elsewhere and
|
||||
body.in.segments is yes)
|
||||
(then class is segments))
|
||||
(rule (if phylum is elsewhere and
|
||||
body.in.segments is no)
|
||||
(then class is unified))
|
||||
(question (variable body.in.segments)
|
||||
(query body.in.segments.query))
|
||||
(rule (if class is breasts and
|
||||
can.eat.meat is yes)
|
||||
(then order is meat))
|
||||
(rule (if class is breasts and
|
||||
can.eat.meat is no)
|
||||
(then order is vegy))
|
||||
(question (variable can.eat.meat)
|
||||
(query can.eat.meat.query))
|
||||
(rule (if class is water and
|
||||
boney is yes)
|
||||
(then type.animal is fish))
|
||||
(rule (if class is water and
|
||||
boney is no)
|
||||
(then type.animal is shark.ray))
|
||||
(question (variable boney)
|
||||
(query boney.query))
|
||||
(rule (if class is dry and
|
||||
scaly is yes)
|
||||
(then order is scales))
|
||||
(rule (if class is dry and
|
||||
scaly is no)
|
||||
(then order is soft))
|
||||
(question (variable scaly)
|
||||
(query scaly.query))
|
||||
(rule (if class is segments and
|
||||
shell is yes)
|
||||
(then order is shell))
|
||||
(rule (if class is segments and
|
||||
shell is no)
|
||||
(then type.animal is centipede.millipede.insect))
|
||||
(question (variable shell)
|
||||
(query shell.query))
|
||||
(rule (if class is unified and
|
||||
digest.cells is yes)
|
||||
(then order is cells))
|
||||
(rule (if class is unified and
|
||||
digest.cells is no)
|
||||
(then order is stomach))
|
||||
(question (variable digest.cells)
|
||||
(query digest.cells.query))
|
||||
(rule (if order is meat and
|
||||
fly is yes)
|
||||
(then type.animal is bat))
|
||||
(rule (if order is meat and
|
||||
fly is no)
|
||||
(then family is nowings))
|
||||
(question (variable fly)
|
||||
(query fly.query))
|
||||
(rule (if order is vegy and
|
||||
hooves is yes)
|
||||
(then family is hooves))
|
||||
(rule (if order is vegy and
|
||||
hooves is no)
|
||||
(then family is feet))
|
||||
(question (variable hooves)
|
||||
(query hooves.query))
|
||||
(rule (if order is scales and
|
||||
rounded.shell is yes)
|
||||
(then type.animal is turtle))
|
||||
(rule (if order is scales and
|
||||
rounded.shell is no)
|
||||
(then family is noshell))
|
||||
(question (variable rounded.shell)
|
||||
(query rounded.shell.query))
|
||||
(rule (if order is soft and
|
||||
jump is yes)
|
||||
(then type.animal is frog))
|
||||
(rule (if order is soft and
|
||||
jump is no)
|
||||
(then type.animal is salamander))
|
||||
(question (variable jump)
|
||||
(query jump.query))
|
||||
(rule (if order is shell and
|
||||
tail is yes)
|
||||
(then type.animal is lobster))
|
||||
(rule (if order is shell and
|
||||
tail is no)
|
||||
(then type.animal is crab))
|
||||
(question (variable tail)
|
||||
(query tail.query))
|
||||
(rule (if order is cells and
|
||||
stationary is yes)
|
||||
(then family is stationary))
|
||||
(rule (if order is cells and
|
||||
stationary is no)
|
||||
(then type.animal is jellyfish))
|
||||
(question (variable stationary)
|
||||
(query stationary.query))
|
||||
(rule (if order is stomach and
|
||||
multicelled is yes)
|
||||
(then family is multicelled))
|
||||
(rule (if order is stomach and
|
||||
multicelled is no)
|
||||
(then type.animal is protozoa))
|
||||
(question (variable multicelled)
|
||||
(query multicelled.query))
|
||||
(rule (if family is nowings and
|
||||
opposing.thumb is yes)
|
||||
(then genus is thumb))
|
||||
(rule (if family is nowings and
|
||||
opposing.thumb is no)
|
||||
(then genus is nothumb))
|
||||
(question (variable opposing.thumb)
|
||||
(query opposing.thumb.query))
|
||||
(rule (if family is hooves and
|
||||
two.toes is yes)
|
||||
(then genus is twotoes))
|
||||
(rule (if family is hooves and
|
||||
two.toes is no)
|
||||
(then genus is onetoe))
|
||||
(question (variable two.toes)
|
||||
(query two.toes.query))
|
||||
(rule (if family is feet and
|
||||
live.in.water is yes)
|
||||
(then genus is water))
|
||||
(rule (if family is feet and
|
||||
live.in.water is no)
|
||||
(then genus is dry))
|
||||
(question (variable live.in.water)
|
||||
(query live.in.water.query))
|
||||
(rule (if family is noshell and
|
||||
limbs is yes)
|
||||
(then type.animal is crocodile.alligator))
|
||||
(rule (if family is noshell and
|
||||
limbs is no)
|
||||
(then type.animal is snake))
|
||||
(question (variable limbs)
|
||||
(query limbs.query))
|
||||
(rule (if family is stationary and
|
||||
spikes is yes)
|
||||
(then type.animal is sea.anemone))
|
||||
(rule (if family is stationary and
|
||||
spikes is no)
|
||||
(then type.animal is coral.sponge))
|
||||
(question (variable spikes)
|
||||
(query spikes.query))
|
||||
(rule (if family is multicelled and
|
||||
spiral.shell is yes)
|
||||
(then type.animal is snail))
|
||||
(rule (if family is multicelled and
|
||||
spiral.shell is no)
|
||||
(then genus is noshell))
|
||||
(question (variable spiral.shell)
|
||||
(query spiral.shell.query))
|
||||
(rule (if genus is thumb and
|
||||
prehensile.tail is yes)
|
||||
(then type.animal is monkey))
|
||||
(rule (if genus is thumb and
|
||||
prehensile.tail is no)
|
||||
(then species is notail))
|
||||
(question (variable prehensile.tail)
|
||||
(query prehensile.tail.query))
|
||||
(rule (if genus is nothumb and
|
||||
over.400 is yes)
|
||||
(then species is 400))
|
||||
(rule (if genus is nothumb and
|
||||
over.400 is no)
|
||||
(then species is under400))
|
||||
(question (variable over.400)
|
||||
(query over.400.query))
|
||||
(rule (if genus is twotoes and
|
||||
horns is yes)
|
||||
(then species is horns))
|
||||
(rule (if genus is twotoes and
|
||||
horns is no)
|
||||
(then species is nohorns))
|
||||
(question (variable horns)
|
||||
(query horns.query))
|
||||
(rule (if genus is onetoe and
|
||||
plating is yes)
|
||||
(then type.animal is rhinoceros))
|
||||
(rule (if genus is onetoe and
|
||||
plating is no)
|
||||
(then type.animal is horse.zebra))
|
||||
(question (variable plating)
|
||||
(query plating.query))
|
||||
(rule (if genus is water and
|
||||
hunted is yes)
|
||||
(then type.animal is whale))
|
||||
(rule (if genus is water and
|
||||
hunted is no)
|
||||
(then type.animal is dolphin.porpoise))
|
||||
(question (variable hunted)
|
||||
(query hunted.query))
|
||||
(rule (if genus is dry and
|
||||
front.teeth is yes)
|
||||
(then species is teeth))
|
||||
(rule (if genus is dry and
|
||||
front.teeth is no)
|
||||
(then species is noteeth))
|
||||
(question (variable front.teeth)
|
||||
(query front.teeth.query))
|
||||
(rule (if genus is noshell and
|
||||
bivalve is yes)
|
||||
(then type.animal is clam.oyster))
|
||||
(rule (if genus is noshell and
|
||||
bivalve is no)
|
||||
(then type.animal is squid.octopus))
|
||||
(question (variable bivalve)
|
||||
(query bivalve.query))
|
||||
(rule (if species is notail and
|
||||
nearly.hairless is yes)
|
||||
(then type.animal is man))
|
||||
(rule (if species is notail and
|
||||
nearly.hairless is no)
|
||||
(then subspecies is hair))
|
||||
(question (variable nearly.hairless)
|
||||
(query nearly.hairless.query))
|
||||
(rule (if species is 400 and
|
||||
land.based is yes)
|
||||
(then type.animal is bear.tiger.lion))
|
||||
(rule (if species is 400 and
|
||||
land.based is no)
|
||||
(then type.animal is walrus))
|
||||
(question (variable land.based)
|
||||
(query land.based.query))
|
||||
(rule (if species is under400 and
|
||||
thintail is yes)
|
||||
(then type.animal is cat))
|
||||
(rule (if species is under400 and
|
||||
thintail is no)
|
||||
(then type.animal is coyote.wolf.fox.dog))
|
||||
(question (variable thintail)
|
||||
(query thintail.query))
|
||||
(rule (if species is nohorns and
|
||||
lives.in.desert is yes)
|
||||
(then type.animal is camel))
|
||||
(rule (if species is nohorns and
|
||||
lives.in.desert is no and
|
||||
semi.aquatic is no)
|
||||
(then type.animal is giraffe))
|
||||
(rule (if species is nohorns and
|
||||
lives.in.desert is no and
|
||||
semi.aquatic is yes)
|
||||
(then type.animal is hippopotamus))
|
||||
(question (variable lives.in.desert)
|
||||
(query lives.in.desert.query))
|
||||
(question (variable semi.aquatic)
|
||||
(query semi.aquatic.query))
|
||||
(rule (if species is teeth and
|
||||
large.ears is yes)
|
||||
(then type.animal is rabbit))
|
||||
(rule (if species is teeth and
|
||||
large.ears is no)
|
||||
(then type.animal is rat.mouse.squirrel.beaver.porcupine))
|
||||
(question (variable large.ears)
|
||||
(query large.ears.query))
|
||||
(rule (if species is noteeth and
|
||||
pouch is yes)
|
||||
(then type.animal is kangaroo.koala.bear))
|
||||
(rule (if species is noteeth and
|
||||
pouch is no)
|
||||
(then type.animal is mole.shrew.elephant))
|
||||
(question (variable pouch)
|
||||
(query pouch.query))
|
||||
(rule (if subspecies is hair and
|
||||
long.powerful.arms is yes)
|
||||
(then type.animal is orangutan.gorilla.chimpanzee))
|
||||
(rule (if subspecies is hair and
|
||||
long.powerful.arms is no)
|
||||
(then type.animal is baboon))
|
||||
(question (variable long.powerful.arms)
|
||||
(query long.powerful.arms.query))
|
||||
(rule (if species is horns and
|
||||
fleece is yes)
|
||||
(then type.animal is sheep.goat))
|
||||
(rule (if species is horns and
|
||||
fleece is no)
|
||||
(then subsubspecies is nofleece))
|
||||
(question (variable fleece)
|
||||
(query fleece.query))
|
||||
(rule (if subsubspecies is nofleece and
|
||||
domesticated is yes)
|
||||
(then type.animal is cow))
|
||||
(rule (if subsubspecies is nofleece and
|
||||
domesticated is no)
|
||||
(then type.animal is deer.moose.antelope))
|
||||
(question (variable domesticated)
|
||||
(query domesticated.query))
|
||||
(answer (prefix "I think your animal is a ") (variable type.animal) (postfix ".")))
|
||||
281
samples/CLIPS/sudoku.clp
Normal file
281
samples/CLIPS/sudoku.clp
Normal file
@@ -0,0 +1,281 @@
|
||||
;;; http://www.angusj.com/sudoku/hints
|
||||
;;; http://www.scanraid.com/BasicStrategies.htm
|
||||
;;; http://www.sudokuoftheday.com/pages/techniques-overview
|
||||
;;; http://www.sudokuonline.us/sudoku_solving_techniques
|
||||
;;; http://www.sadmansoftware.com/sudoku/techniques.htm
|
||||
;;; http://www.krazydad.com/blog/2005/09/29/an-index-of-sudoku-strategies/
|
||||
|
||||
;;; #######################
|
||||
;;; DEFTEMPLATES & DEFFACTS
|
||||
;;; #######################
|
||||
|
||||
(deftemplate possible
|
||||
(slot row)
|
||||
(slot column)
|
||||
(slot value)
|
||||
(slot group)
|
||||
(slot id))
|
||||
|
||||
(deftemplate impossible
|
||||
(slot id)
|
||||
(slot value)
|
||||
(slot priority)
|
||||
(slot reason))
|
||||
|
||||
(deftemplate technique-employed
|
||||
(slot reason)
|
||||
(slot priority))
|
||||
|
||||
(deftemplate technique
|
||||
(slot name)
|
||||
(slot priority))
|
||||
|
||||
(deffacts startup
|
||||
(phase grid-values))
|
||||
|
||||
(deftemplate size-value
|
||||
(slot size)
|
||||
(slot value))
|
||||
|
||||
(deffacts values
|
||||
(size-value (size 1) (value 1))
|
||||
(size-value (size 2) (value 2))
|
||||
(size-value (size 2) (value 3))
|
||||
(size-value (size 2) (value 4))
|
||||
(size-value (size 3) (value 5))
|
||||
(size-value (size 3) (value 6))
|
||||
(size-value (size 3) (value 7))
|
||||
(size-value (size 3) (value 8))
|
||||
(size-value (size 3) (value 9))
|
||||
(size-value (size 4) (value 10))
|
||||
(size-value (size 4) (value 11))
|
||||
(size-value (size 4) (value 12))
|
||||
(size-value (size 4) (value 13))
|
||||
(size-value (size 4) (value 14))
|
||||
(size-value (size 4) (value 15))
|
||||
(size-value (size 4) (value 16))
|
||||
(size-value (size 5) (value 17))
|
||||
(size-value (size 5) (value 18))
|
||||
(size-value (size 5) (value 19))
|
||||
(size-value (size 5) (value 20))
|
||||
(size-value (size 5) (value 21))
|
||||
(size-value (size 5) (value 22))
|
||||
(size-value (size 5) (value 23))
|
||||
(size-value (size 5) (value 24))
|
||||
(size-value (size 5) (value 25)))
|
||||
|
||||
;;; ###########
|
||||
;;; SETUP RULES
|
||||
;;; ###########
|
||||
|
||||
;;; ***********
|
||||
;;; stress-test
|
||||
;;; ***********
|
||||
|
||||
(defrule stress-test
|
||||
|
||||
(declare (salience 10))
|
||||
|
||||
(phase match)
|
||||
|
||||
(stress-test)
|
||||
|
||||
(priority ?last)
|
||||
|
||||
(not (priority ?p&:(> ?p ?last)))
|
||||
|
||||
(technique (priority ?next&:(> ?next ?last)))
|
||||
|
||||
(not (technique (priority ?p&:(> ?p ?last)&:(< ?p ?next))))
|
||||
|
||||
=>
|
||||
|
||||
(assert (priority ?next)))
|
||||
|
||||
;;; *****************
|
||||
;;; enable-techniques
|
||||
;;; *****************
|
||||
|
||||
(defrule enable-techniques
|
||||
|
||||
(declare (salience 10))
|
||||
|
||||
(phase match)
|
||||
|
||||
(size ?)
|
||||
|
||||
(not (possible (value any)))
|
||||
|
||||
=>
|
||||
|
||||
(assert (priority 1)))
|
||||
|
||||
;;; **********
|
||||
;;; expand-any
|
||||
;;; **********
|
||||
|
||||
(defrule expand-any
|
||||
|
||||
(declare (salience 10))
|
||||
|
||||
(phase expand-any)
|
||||
|
||||
?f <- (possible (row ?r) (column ?c) (value any) (group ?g) (id ?id))
|
||||
|
||||
(not (possible (value any) (id ?id2&:(< ?id2 ?id))))
|
||||
|
||||
(size ?s)
|
||||
|
||||
(size-value (size ?as&:(<= ?as ?s)) (value ?v))
|
||||
|
||||
(not (possible (row ?r) (column ?c) (value ?v)))
|
||||
|
||||
(not (and (size-value (value ?v2&:(< ?v2 ?v)))
|
||||
|
||||
(not (possible (row ?r) (column ?c) (value ?v2)))))
|
||||
|
||||
=>
|
||||
|
||||
(assert (possible (row ?r) (column ?c) (value ?v) (group ?g) (id ?id))))
|
||||
|
||||
;;; *****************
|
||||
;;; position-expanded
|
||||
;;; *****************
|
||||
|
||||
(defrule position-expanded
|
||||
|
||||
(declare (salience 10))
|
||||
|
||||
(phase expand-any)
|
||||
|
||||
?f <- (possible (row ?r) (column ?c) (value any) (group ?g) (id ?id))
|
||||
|
||||
(size ?s)
|
||||
|
||||
(not (and (size-value (size ?as&:(<= ?as ?s)) (value ?v))
|
||||
|
||||
(not (possible (row ?r) (column ?c) (value ?v)))))
|
||||
|
||||
=>
|
||||
|
||||
(retract ?f))
|
||||
|
||||
;;; ###########
|
||||
;;; PHASE RULES
|
||||
;;; ###########
|
||||
|
||||
;;; ***************
|
||||
;;; expand-any-done
|
||||
;;; ***************
|
||||
|
||||
(defrule expand-any-done
|
||||
|
||||
(declare (salience 10))
|
||||
|
||||
?f <- (phase expand-any)
|
||||
|
||||
(not (possible (value any)))
|
||||
|
||||
=>
|
||||
|
||||
(retract ?f)
|
||||
|
||||
(assert (phase initial-output))
|
||||
(assert (print-position 1 1)))
|
||||
|
||||
;;; ***********
|
||||
;;; begin-match
|
||||
;;; ***********
|
||||
|
||||
(defrule begin-match
|
||||
|
||||
(declare (salience -20))
|
||||
|
||||
?f <- (phase initial-output)
|
||||
|
||||
=>
|
||||
|
||||
(retract ?f)
|
||||
|
||||
(assert (phase match)))
|
||||
|
||||
;;; *****************
|
||||
;;; begin-elimination
|
||||
;;; *****************
|
||||
|
||||
(defrule begin-elimination
|
||||
|
||||
(declare (salience -20))
|
||||
|
||||
?f <- (phase match)
|
||||
|
||||
(not (not (impossible)))
|
||||
|
||||
=>
|
||||
|
||||
(retract ?f)
|
||||
|
||||
(assert (phase elimination)))
|
||||
|
||||
;;; *************
|
||||
;;; next-priority
|
||||
;;; *************
|
||||
|
||||
(defrule next-priority
|
||||
|
||||
(declare (salience -20))
|
||||
|
||||
(phase match)
|
||||
|
||||
(not (impossible))
|
||||
|
||||
(priority ?last)
|
||||
|
||||
(not (priority ?p&:(> ?p ?last)))
|
||||
|
||||
(technique (priority ?next&:(> ?next ?last)))
|
||||
|
||||
(not (technique (priority ?p&:(> ?p ?last)&:(< ?p ?next))))
|
||||
|
||||
=>
|
||||
|
||||
(assert (priority ?next)))
|
||||
|
||||
;;; ************
|
||||
;;; begin-output
|
||||
;;; ************
|
||||
|
||||
(defrule begin-output
|
||||
|
||||
(declare (salience -20))
|
||||
|
||||
?f <- (phase match)
|
||||
|
||||
(not (impossible))
|
||||
|
||||
(priority ?last)
|
||||
|
||||
(not (priority ?p&:(> ?p ?last)))
|
||||
|
||||
(not (technique (priority ?next&:(> ?next ?last))))
|
||||
|
||||
=>
|
||||
|
||||
(retract ?f)
|
||||
|
||||
(assert (phase final-output))
|
||||
(assert (print-position 1 1)))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
133
samples/Forth/tools.4TH
Normal file
133
samples/Forth/tools.4TH
Normal file
@@ -0,0 +1,133 @@
|
||||
\ -*- forth -*- Copyright 2004, 2013 Lars Brinkhoff
|
||||
|
||||
( Tools words. )
|
||||
|
||||
: .s ( -- )
|
||||
[char] < emit depth (.) ." > "
|
||||
'SP @ >r r@ depth 1- cells +
|
||||
begin
|
||||
dup r@ <>
|
||||
while
|
||||
dup @ .
|
||||
/cell -
|
||||
repeat r> 2drop ;
|
||||
|
||||
: ? @ . ;
|
||||
|
||||
: c? c@ . ;
|
||||
|
||||
: dump bounds do i ? /cell +loop cr ;
|
||||
|
||||
: cdump bounds do i c? loop cr ;
|
||||
|
||||
: again postpone branch , ; immediate
|
||||
|
||||
: see-find ( caddr -- end xt )
|
||||
>r here lastxt @
|
||||
begin
|
||||
dup 0= abort" Undefined word"
|
||||
dup r@ word= if r> drop exit then
|
||||
nip dup >nextxt
|
||||
again ;
|
||||
|
||||
: cabs ( char -- |char| ) dup 127 > if 256 swap - then ;
|
||||
|
||||
: xt. ( xt -- )
|
||||
( >name ) count cabs type ;
|
||||
|
||||
: xt? ( xt -- flag )
|
||||
>r lastxt @ begin
|
||||
?dup
|
||||
while
|
||||
dup r@ = if r> 2drop -1 exit then
|
||||
>nextxt
|
||||
repeat r> drop 0 ;
|
||||
|
||||
: disassemble ( x -- )
|
||||
dup xt? if
|
||||
( >name ) count
|
||||
dup 127 > if ." postpone " then
|
||||
cabs type
|
||||
else
|
||||
.
|
||||
then ;
|
||||
|
||||
: .addr dup . ;
|
||||
|
||||
: see-line ( addr -- )
|
||||
cr ." ( " .addr ." ) " @ disassemble ;
|
||||
|
||||
: see-word ( end xt -- )
|
||||
>r ." : " r@ xt.
|
||||
r@ >body do i see-line /cell +loop
|
||||
." ;" r> c@ 127 > if ." immediate" then ;
|
||||
|
||||
: see bl word see-find see-word cr ;
|
||||
|
||||
: #body bl word see-find >body - ;
|
||||
|
||||
: type-word ( end xt -- flag )
|
||||
xt. space drop 0 ;
|
||||
|
||||
: traverse-dictionary ( in.. xt -- out.. )
|
||||
\ xt execution: ( in.. end xt2 -- in.. 0 | in.. end xt2 -- out.. true )
|
||||
>r here lastxt @ begin
|
||||
?dup
|
||||
while
|
||||
r> 2dup >r >r execute
|
||||
if r> r> 2drop exit then
|
||||
r> dup >nextxt
|
||||
repeat r> 2drop ;
|
||||
|
||||
: words ( -- )
|
||||
['] type-word traverse-dictionary cr ;
|
||||
|
||||
\ ----------------------------------------------------------------------
|
||||
|
||||
( Tools extension words. )
|
||||
|
||||
\ ;code
|
||||
|
||||
\ assembler
|
||||
|
||||
\ in kernel: bye
|
||||
|
||||
\ code
|
||||
|
||||
\ cs-pick
|
||||
|
||||
\ cs-roll
|
||||
|
||||
\ editor
|
||||
|
||||
: forget ' dup >nextxt lastxt ! 'here ! reveal ;
|
||||
|
||||
\ Kernel: state
|
||||
|
||||
\ [else]
|
||||
|
||||
\ [if]
|
||||
|
||||
\ [then]
|
||||
|
||||
\ ----------------------------------------------------------------------
|
||||
|
||||
( Forth2012 tools extension words. )
|
||||
|
||||
\ TODO: n>r
|
||||
|
||||
\ TODO: nr>
|
||||
|
||||
\ TODO: synonym
|
||||
|
||||
: [undefined] bl-word find nip 0= ; immediate
|
||||
|
||||
: [defined] postpone [undefined] invert ; immediate
|
||||
|
||||
\ ----------------------------------------------------------------------
|
||||
|
||||
: @+ ( addr -- addr+/cell x ) dup cell+ swap @ ;
|
||||
|
||||
: !+ ( x addr -- addr+/cell ) tuck ! cell+ ;
|
||||
|
||||
: -rot swap >r swap r> ;
|
||||
73
samples/J/stwij.ijs
Normal file
73
samples/J/stwij.ijs
Normal file
@@ -0,0 +1,73 @@
|
||||
NB. From "Continuing to write in J".
|
||||
NB. See http://www.jsoftware.com/help/jforc/continuing_to_write_in_j.htm
|
||||
|
||||
empno=: 316 317 319 320
|
||||
payrate=: 60 42 44 54
|
||||
billrate=: 120 90 90 108
|
||||
clientlist=: 10011 10012 10025
|
||||
emp_client=: 10012 10025 10012 10025
|
||||
hoursworked=: 4 31 $ 8 0 3 10 9 8 8 9 4 0 8 7 10 10 12 9 0 6 8 9 9 9 0 0 10 11 9 7 10 2 0 8 0 0 9 9 8 9 10 0 0 8 8 10 7 10 0 0 7 8 9 8 9 0 4 9 8 9 8 9 0 0 5 0 0 8 9 9 9 9 0 0 8 7 0 0 9 0 2 10 10 9 11 8 0 0 8 9 10 8 9 0 0 9 0 0 9 10 8 6 6 8 0 9 8 10 6 9 7 0 6 8 8 8 9 0 5 8 9 8 8 12 0 0
|
||||
|
||||
NB. Finds the number of hours each employee worked in the given month.
|
||||
emphours=: 3 : '+/"1 hoursworked'
|
||||
|
||||
NB. Determines the wages earned by each employee in the given month.
|
||||
empearnings=: 3 : 'payrate * +/"1 hoursworked'
|
||||
|
||||
NB. Determines the profit brought in by each employee.
|
||||
empprofit=: 3 : 0
|
||||
(billrate - payrate) * +/"1 hoursworked
|
||||
)
|
||||
|
||||
NB. Returns the amount to bill a given client.
|
||||
billclient=: 3 : 0
|
||||
mask=. emp_client = y
|
||||
+/ (mask # billrate) * +/"1 mask # hoursworked
|
||||
)
|
||||
|
||||
NB. Finds for each day of the month the employee who billed the most hours.
|
||||
dailydrudge=: 3 : 0
|
||||
((|: hoursworked) i."1 0 >./ hoursworked) { empno
|
||||
)
|
||||
|
||||
NB. Returns the employees, in descending order of the profit brought in by each.
|
||||
producers=: 3 : 'empno \: empprofit 0'
|
||||
|
||||
NB. Returns the clients, in descending order of the profit generated by each.
|
||||
custbyprofit=: 3 : 0
|
||||
clientlist \: +/ (clientlist ="1 0 emp_client) * empprofit 0
|
||||
)
|
||||
|
||||
NB. Calculates withholding tax on each employee's earnings.
|
||||
renderuntocaesar=: 3 : 0
|
||||
bktmin=. 0 6000 10000 20000 NB. Four brackets, 0..6000..10000..20000.._
|
||||
bktrate=. 0.05 0.10 0.20 0.30
|
||||
bktearns=. 0 >. ((1 |.!._ bktmin) <."1 0 empearnings'') -"1 bktmin
|
||||
+/"1 bktrate *"1 bktearns
|
||||
)
|
||||
|
||||
NB. Main
|
||||
|
||||
echo 'Problem 1'
|
||||
echo emphours''
|
||||
|
||||
echo 'Problem 2'
|
||||
echo empearnings''
|
||||
|
||||
echo 'Problem 3'
|
||||
echo empprofit''
|
||||
|
||||
echo 'Problem 4'
|
||||
echo billclient 10025
|
||||
|
||||
echo 'Problem 5'
|
||||
echo dailydrudge''
|
||||
|
||||
echo 'Problem 6'
|
||||
echo producers''
|
||||
|
||||
echo 'Problem 7'
|
||||
echo custbyprofit''
|
||||
|
||||
echo 'Problem 8'
|
||||
echo 0j2 ": renderuntocaesar''
|
||||
5281
samples/Modelica/Translational.mo
Normal file
5281
samples/Modelica/Translational.mo
Normal file
File diff suppressed because it is too large
Load Diff
285
samples/Modelica/modelica.mo
Normal file
285
samples/Modelica/modelica.mo
Normal file
@@ -0,0 +1,285 @@
|
||||
within Modelica.Electrical.Analog;
|
||||
package Sensors "Potential, voltage, current, and power sensors"
|
||||
|
||||
extends Modelica.Icons.SensorsPackage;
|
||||
|
||||
model PotentialSensor "Sensor to measure the potential"
|
||||
extends Modelica.Icons.RotationalSensor;
|
||||
|
||||
Interfaces.PositivePin p "pin to be measured" annotation (Placement(
|
||||
transformation(extent={{-110,-10},{-90,10}}, rotation=0)));
|
||||
Modelica.Blocks.Interfaces.RealOutput phi
|
||||
"Absolute voltage potential as output signal"
|
||||
annotation (Placement(transformation(extent={{100,-10},{120,10}},
|
||||
rotation=0)));
|
||||
equation
|
||||
p.i = 0;
|
||||
phi = p.v;
|
||||
annotation (
|
||||
Icon(coordinateSystem(
|
||||
preserveAspectRatio=true,
|
||||
extent={{-100,-100},{100,100}},
|
||||
grid={1,1}), graphics={
|
||||
Text(
|
||||
extent={{-29,-11},{30,-70}},
|
||||
lineColor={0,0,0},
|
||||
textString="V"),
|
||||
Line(points={{-70,0},{-90,0}}, color={0,0,0}),
|
||||
Line(points={{100,0},{70,0}}, color={0,0,255}),
|
||||
Text(
|
||||
extent={{-150,80},{150,120}},
|
||||
textString="%name",
|
||||
lineColor={0,0,255})}),
|
||||
Diagram(coordinateSystem(
|
||||
preserveAspectRatio=true,
|
||||
extent={{-100,-100},{100,100}},
|
||||
grid={1,1}), graphics={Line(points={{-70,0},{-96,0}}, color={0,0,0}),
|
||||
Line(points={{100,0},{70,0}}, color={0,0,255})}),
|
||||
Documentation(revisions="<html>
|
||||
<ul>
|
||||
<li><i> 1998 </i>
|
||||
by Christoph Clauss<br> initially implemented<br>
|
||||
</li>
|
||||
</ul>
|
||||
</html>", info="<html>
|
||||
<p>The potential sensor converts the voltage of a node (with respect to the ground node) into a real valued signal. It does not influence the current sum at the node which voltage is measured, therefore, the electrical behavior is not influenced by the sensor.</p>
|
||||
</html>"));
|
||||
end PotentialSensor;
|
||||
|
||||
model VoltageSensor "Sensor to measure the voltage between two pins"
|
||||
extends Modelica.Icons.RotationalSensor;
|
||||
|
||||
Interfaces.PositivePin p "positive pin" annotation (Placement(
|
||||
transformation(extent={{-110,-10},{-90,10}}, rotation=0)));
|
||||
Interfaces.NegativePin n "negative pin" annotation (Placement(
|
||||
transformation(extent={{90,-10},{110,10}}, rotation=0)));
|
||||
Modelica.Blocks.Interfaces.RealOutput v
|
||||
"Voltage between pin p and n (= p.v - n.v) as output signal"
|
||||
annotation (Placement(transformation(
|
||||
origin={0,-100},
|
||||
extent={{10,-10},{-10,10}},
|
||||
rotation=90)));
|
||||
|
||||
equation
|
||||
p.i = 0;
|
||||
n.i = 0;
|
||||
v = p.v - n.v;
|
||||
annotation (
|
||||
Icon(coordinateSystem(
|
||||
preserveAspectRatio=true,
|
||||
extent={{-100,-100},{100,100}},
|
||||
grid={1,1}), graphics={
|
||||
Text(
|
||||
extent={{-29,-11},{30,-70}},
|
||||
lineColor={0,0,0},
|
||||
textString="V"),
|
||||
Line(points={{-70,0},{-90,0}}, color={0,0,0}),
|
||||
Line(points={{70,0},{90,0}}, color={0,0,0}),
|
||||
Line(points={{0,-90},{0,-70}}, color={0,0,255}),
|
||||
Text(
|
||||
extent={{-150,80},{150,120}},
|
||||
textString="%name",
|
||||
lineColor={0,0,255})}),
|
||||
Diagram(coordinateSystem(
|
||||
preserveAspectRatio=true,
|
||||
extent={{-100,-100},{100,100}},
|
||||
grid={1,1}), graphics={
|
||||
Line(points={{-70,0},{-96,0}}, color={0,0,0}),
|
||||
Line(points={{70,0},{96,0}}, color={0,0,0}),
|
||||
Line(points={{0,-90},{0,-70}}, color={0,0,255})}),
|
||||
Documentation(revisions="<html>
|
||||
<ul>
|
||||
<li><i> 1998 </i>
|
||||
by Christoph Clauss<br> initially implemented<br>
|
||||
</li>
|
||||
</ul>
|
||||
</html>", info="<html>
|
||||
<p>The voltage sensor converts the voltage between the two connectors into a real valued signal. It does not influence the current sum at the nodes in between the voltage is measured, therefore, the electrical behavior is not influenced by the sensor.</p>
|
||||
</html>"));
|
||||
end VoltageSensor;
|
||||
|
||||
model CurrentSensor "Sensor to measure the current in a branch"
|
||||
extends Modelica.Icons.RotationalSensor;
|
||||
|
||||
Interfaces.PositivePin p "positive pin" annotation (Placement(
|
||||
transformation(extent={{-110,-10},{-90,10}}, rotation=0)));
|
||||
Interfaces.NegativePin n "negative pin" annotation (Placement(
|
||||
transformation(extent={{90,-10},{110,10}}, rotation=0)));
|
||||
Modelica.Blocks.Interfaces.RealOutput i
|
||||
"current in the branch from p to n as output signal"
|
||||
annotation (Placement(transformation(
|
||||
origin={0,-100},
|
||||
extent={{10,-10},{-10,10}},
|
||||
rotation=90)));
|
||||
|
||||
equation
|
||||
p.v = n.v;
|
||||
p.i = i;
|
||||
n.i = -i;
|
||||
annotation (
|
||||
Icon(coordinateSystem(
|
||||
preserveAspectRatio=true,
|
||||
extent={{-100,-100},{100,100}},
|
||||
grid={1,1}), graphics={
|
||||
Text(
|
||||
extent={{-29,-11},{30,-70}},
|
||||
lineColor={0,0,0},
|
||||
textString="A"),
|
||||
Line(points={{-70,0},{-90,0}}, color={0,0,0}),
|
||||
Text(
|
||||
extent={{-150,80},{150,120}},
|
||||
textString="%name",
|
||||
lineColor={0,0,255}),
|
||||
Line(points={{70,0},{90,0}}, color={0,0,0}),
|
||||
Line(points={{0,-90},{0,-70}}, color={0,0,255})}),
|
||||
Diagram(coordinateSystem(
|
||||
preserveAspectRatio=true,
|
||||
extent={{-100,-100},{100,100}},
|
||||
grid={1,1}), graphics={
|
||||
Text(
|
||||
extent={{-153,79},{147,119}},
|
||||
textString="%name",
|
||||
lineColor={0,0,255}),
|
||||
Line(points={{-70,0},{-96,0}}, color={0,0,0}),
|
||||
Line(points={{70,0},{96,0}}, color={0,0,0}),
|
||||
Line(points={{0,-90},{0,-70}}, color={0,0,255})}),
|
||||
Documentation(revisions="<html>
|
||||
<ul>
|
||||
<li><i> 1998 </i>
|
||||
by Christoph Clauss<br> initially implemented<br>
|
||||
</li>
|
||||
</ul>
|
||||
</html>", info="<html>
|
||||
<p>The current sensor converts the current flowing between the two connectors into a real valued signal. The two connectors are in the sensor connected like a short cut. The sensor has to be placed within an electrical connection in series. It does not influence the current sum at the connected nodes. Therefore, the electrical behavior is not influenced by the sensor.</p>
|
||||
</html>"));
|
||||
end CurrentSensor;
|
||||
|
||||
model PowerSensor "Sensor to measure the power"
|
||||
|
||||
Modelica.Electrical.Analog.Interfaces.PositivePin pc
|
||||
"Positive pin, current path"
|
||||
annotation (Placement(transformation(extent={{-90,-10},{-110,10}}, rotation=
|
||||
0)));
|
||||
Modelica.Electrical.Analog.Interfaces.NegativePin nc
|
||||
"Negative pin, current path"
|
||||
annotation (Placement(transformation(extent={{110,-10},{90,10}}, rotation=0)));
|
||||
Modelica.Electrical.Analog.Interfaces.PositivePin pv
|
||||
"Positive pin, voltage path"
|
||||
annotation (Placement(transformation(extent={{-10,110},{10,90}}, rotation=0)));
|
||||
Modelica.Electrical.Analog.Interfaces.NegativePin nv
|
||||
"Negative pin, voltage path"
|
||||
annotation (Placement(transformation(extent={{10,-110},{-10,-90}}, rotation=
|
||||
0)));
|
||||
Modelica.Blocks.Interfaces.RealOutput power
|
||||
annotation (Placement(transformation(
|
||||
origin={-80,-110},
|
||||
extent={{-10,10},{10,-10}},
|
||||
rotation=270)));
|
||||
Modelica.Electrical.Analog.Sensors.VoltageSensor voltageSensor
|
||||
annotation (Placement(transformation(
|
||||
origin={0,-30},
|
||||
extent={{10,-10},{-10,10}},
|
||||
rotation=90)));
|
||||
Modelica.Electrical.Analog.Sensors.CurrentSensor currentSensor
|
||||
annotation (Placement(transformation(extent={{-50,-10},{-30,10}}, rotation=
|
||||
0)));
|
||||
Modelica.Blocks.Math.Product product
|
||||
annotation (Placement(transformation(
|
||||
origin={-30,-50},
|
||||
extent={{-10,-10},{10,10}},
|
||||
rotation=270)));
|
||||
|
||||
equation
|
||||
connect(pv, voltageSensor.p) annotation (Line(points={{0,100},{0,-20},{
|
||||
6.12323e-016,-20}}, color={0,0,255}));
|
||||
connect(voltageSensor.n, nv) annotation (Line(points={{-6.12323e-016,-40},{
|
||||
-6.12323e-016,-63},{0,-63},{0,-100}}, color={0,0,255}));
|
||||
connect(pc, currentSensor.p)
|
||||
annotation (Line(points={{-100,0},{-50,0}}, color={0,0,255}));
|
||||
connect(currentSensor.n, nc)
|
||||
annotation (Line(points={{-30,0},{100,0}}, color={0,0,255}));
|
||||
connect(currentSensor.i, product.u2) annotation (Line(points={{-40,-10},{-40,
|
||||
-30},{-36,-30},{-36,-38}}, color={0,0,127}));
|
||||
connect(voltageSensor.v, product.u1) annotation (Line(points={{10,-30},{-24,
|
||||
-30},{-24,-38}}, color={0,0,127}));
|
||||
connect(product.y, power) annotation (Line(points={{-30,-61},{-30,-80},{-80,
|
||||
-80},{-80,-110}}, color={0,0,127}));
|
||||
annotation (Icon(coordinateSystem(
|
||||
preserveAspectRatio=true,
|
||||
extent={{-100,-100},{100,100}},
|
||||
grid={2,2}), graphics={
|
||||
Ellipse(
|
||||
extent={{-70,70},{70,-70}},
|
||||
lineColor={0,0,0},
|
||||
fillColor={255,255,255},
|
||||
fillPattern=FillPattern.Solid),
|
||||
Line(points={{0,100},{0,70}}, color={0,0,255}),
|
||||
Line(points={{0,-70},{0,-100}}, color={0,0,255}),
|
||||
Line(points={{-80,-100},{-80,0}}, color={0,0,255}),
|
||||
Line(points={{-100,0},{100,0}}, color={0,0,255}),
|
||||
Text(
|
||||
extent={{150,120},{-150,160}},
|
||||
textString="%name",
|
||||
lineColor={0,0,255}),
|
||||
Line(points={{0,70},{0,40}}, color={0,0,0}),
|
||||
Line(points={{22.9,32.8},{40.2,57.3}}, color={0,0,0}),
|
||||
Line(points={{-22.9,32.8},{-40.2,57.3}}, color={0,0,0}),
|
||||
Line(points={{37.6,13.7},{65.8,23.9}}, color={0,0,0}),
|
||||
Line(points={{-37.6,13.7},{-65.8,23.9}}, color={0,0,0}),
|
||||
Line(points={{0,0},{9.02,28.6}}, color={0,0,0}),
|
||||
Polygon(
|
||||
points={{-0.48,31.6},{18,26},{18,57.2},{-0.48,31.6}},
|
||||
lineColor={0,0,0},
|
||||
fillColor={0,0,0},
|
||||
fillPattern=FillPattern.Solid),
|
||||
Ellipse(
|
||||
extent={{-5,5},{5,-5}},
|
||||
lineColor={0,0,0},
|
||||
fillColor={0,0,0},
|
||||
fillPattern=FillPattern.Solid),
|
||||
Text(
|
||||
extent={{-29,-11},{30,-70}},
|
||||
lineColor={0,0,0},
|
||||
textString="P")}),
|
||||
Diagram(coordinateSystem(
|
||||
preserveAspectRatio=true,
|
||||
extent={{-100,-100},{100,100}},
|
||||
grid={2,2}), graphics),
|
||||
Documentation(info="<html>
|
||||
<p>This power sensor measures instantaneous electrical power of a singlephase system and has a separated voltage and current path. The pins of the voltage path are pv and nv, the pins of the current path are pc and nc. The internal resistance of the current path is zero, the internal resistance of the voltage path is infinite.</p>
|
||||
</html>", revisions="<html>
|
||||
<ul>
|
||||
<li><i>January 12, 2006</i> by Anton Haumer implemented</li>
|
||||
</ul>
|
||||
</html>"));
|
||||
end PowerSensor;
|
||||
annotation (
|
||||
Documentation(info="<html>
|
||||
<p>This package contains potential, voltage, and current sensors. The sensors can be used to convert voltages or currents into real signal values o be connected to components of the Blocks package. The sensors are designed in such a way that they do not influence the electrical behavior.</p>
|
||||
</html>",
|
||||
revisions="<html>
|
||||
<dl>
|
||||
<dt>
|
||||
<b>Main Authors:</b>
|
||||
<dd>
|
||||
Christoph Clauß
|
||||
<<a href=\"mailto:Christoph.Clauss@eas.iis.fraunhofer.de\">Christoph.Clauss@eas.iis.fraunhofer.de</a>><br>
|
||||
André Schneider
|
||||
<<a href=\"mailto:Andre.Schneider@eas.iis.fraunhofer.de\">Andre.Schneider@eas.iis.fraunhofer.de</a>><br>
|
||||
Fraunhofer Institute for Integrated Circuits<br>
|
||||
Design Automation Department<br>
|
||||
Zeunerstraße 38<br>
|
||||
D-01069 Dresden<br>
|
||||
<p>
|
||||
<dt>
|
||||
<b>Copyright:</b>
|
||||
<dd>
|
||||
Copyright © 1998-2010, Modelica Association and Fraunhofer-Gesellschaft.<br>
|
||||
<i>The Modelica package is <b>free</b> software; it can be redistributed and/or modified
|
||||
under the terms of the <b>Modelica license</b>, see the license conditions
|
||||
and the accompanying <b>disclaimer</b> in the documentation of package
|
||||
Modelica in file \"Modelica/package.mo\".</i><br>
|
||||
<p>
|
||||
</dl>
|
||||
</html>"));
|
||||
end Sensors;
|
||||
@@ -1 +1 @@
|
||||
; -*-Smalltalk-*-
|
||||
; -*-mode:Smalltalk-*-
|
||||
|
||||
2
vendor/grammars/AutoHotkey
vendored
2
vendor/grammars/AutoHotkey
vendored
Submodule vendor/grammars/AutoHotkey updated: 371f9b2307...9b42c86e75
1
vendor/grammars/CLIPS-sublime
vendored
Submodule
1
vendor/grammars/CLIPS-sublime
vendored
Submodule
Submodule vendor/grammars/CLIPS-sublime added at f6904baa78
1
vendor/grammars/Creole
vendored
Submodule
1
vendor/grammars/Creole
vendored
Submodule
Submodule vendor/grammars/Creole added at bac4656c8d
1
vendor/grammars/GDScript-sublime
vendored
Submodule
1
vendor/grammars/GDScript-sublime
vendored
Submodule
Submodule vendor/grammars/GDScript-sublime added at 99a0d51224
1
vendor/grammars/JSyntax
vendored
Submodule
1
vendor/grammars/JSyntax
vendored
Submodule
Submodule vendor/grammars/JSyntax added at 74971149b5
1
vendor/grammars/Modelica
vendored
Submodule
1
vendor/grammars/Modelica
vendored
Submodule
Submodule vendor/grammars/Modelica added at d7e50e39c1
2
vendor/grammars/NimLime
vendored
2
vendor/grammars/NimLime
vendored
Submodule vendor/grammars/NimLime updated: 1be33dac08...75811539ec
1
vendor/grammars/ats.sublime
vendored
Submodule
1
vendor/grammars/ats.sublime
vendored
Submodule
Submodule vendor/grammars/ats.sublime added at d954ef6b27
2
vendor/grammars/ceylon-sublimetext
vendored
2
vendor/grammars/ceylon-sublimetext
vendored
Submodule vendor/grammars/ceylon-sublimetext updated: a81ad702b4...070298013e
2
vendor/grammars/factor
vendored
2
vendor/grammars/factor
vendored
Submodule vendor/grammars/factor updated: 14b3261bef...4ada328880
2
vendor/grammars/fsharpbinding
vendored
2
vendor/grammars/fsharpbinding
vendored
Submodule vendor/grammars/fsharpbinding updated: f8dd50c35c...92d969b197
2
vendor/grammars/haxe-sublime-bundle
vendored
2
vendor/grammars/haxe-sublime-bundle
vendored
Submodule vendor/grammars/haxe-sublime-bundle updated: 6359431d88...50c5aa0e10
2
vendor/grammars/latex.tmbundle
vendored
2
vendor/grammars/latex.tmbundle
vendored
Submodule vendor/grammars/latex.tmbundle updated: 2e8d7c9397...16154cef75
2
vendor/grammars/mercury-tmlanguage
vendored
2
vendor/grammars/mercury-tmlanguage
vendored
Submodule vendor/grammars/mercury-tmlanguage updated: eaef0b0643...1cb8e94922
2
vendor/grammars/objective-c.tmbundle
vendored
2
vendor/grammars/objective-c.tmbundle
vendored
Submodule vendor/grammars/objective-c.tmbundle updated: 33c6be4028...8387be8975
1
vendor/grammars/sublime-apl
vendored
Submodule
1
vendor/grammars/sublime-apl
vendored
Submodule
Submodule vendor/grammars/sublime-apl added at a8c36775d5
1
vendor/grammars/sublime-golo
vendored
Submodule
1
vendor/grammars/sublime-golo
vendored
Submodule
Submodule vendor/grammars/sublime-golo added at 2c0707bd4f
Reference in New Issue
Block a user