Add all the A tasks

This commit is contained in:
Ingy döt Net 2013-04-10 14:58:50 -07:00
parent 2dd7375f96
commit 051504d65b
1608 changed files with 18584 additions and 0 deletions

1
Task/A+B/0815/a+b.0815 Normal file
View file

@ -0,0 +1 @@
|x|+%

23
Task/A+B/0DESCRIPTION Normal file
View file

@ -0,0 +1,23 @@
'''A+B''' - in programming contests, classic problem, which is given so contestants can gain familiarity with online judging system being used.
'''Problem statement'''<br>
Given 2 integer numbers, A and B. One needs to find their sum.
:'''Input data'''<br>
:Two integer numbers are written in the input stream, separated by space.
:<math>(-1000 \le A,B \le +1000)</math>
:'''Output data'''<br>
:The required output is one integer: the sum of A and B.
:'''Example:'''<br>
::{|class="standard"
! Input
! Output
|-
|<tt>2 2</tt>
|<tt>4</tt>
|-
|<tt>3 2</tt>
|<tt>5</tt>
|}

15
Task/A+B/ABAP/a+b.abap Normal file
View file

@ -0,0 +1,15 @@
report z_sum_a_b.
data: lv_output type i.
selection-screen begin of block input.
parameters:
p_first type i,
p_second type i.
selection-screen end of block input.
at selection-screen output.
%_p_first_%_app_%-text = 'First Number: '.
%_p_second_%_app_%-text = 'Second Number: '.
start-of-selection.
lv_output = p_first + p_second.
write : / lv_output.

View file

@ -0,0 +1 @@
print((read int + read int))

View file

@ -0,0 +1,3 @@
open(stand in, "input.txt", stand in channel);
open(stand out, "output.txt", stand out channel);
print((read int + read int))

14
Task/A+B/ANTLR/a+b.antlr Normal file
View file

@ -0,0 +1,14 @@
grammar aplusb ;
options {
language = Java;
}
aplusb : (WS* e1=Num WS+ e2=Num NEWLINE {System.out.println($e1.text + " + " + $e2.text + " = " + (Integer.parseInt($e1.text) + Integer.parseInt($e2.text)));})+
;
Num : '-'?('0'..'9')+
;
WS : (' ' | '\t')
;
NEWLINE : WS* '\r'? '\n'
;

1
Task/A+B/AWK/a+b.awk Normal file
View file

@ -0,0 +1 @@
{print $1 + $2}

10
Task/A+B/Ada/a+b-1.ada Normal file
View file

@ -0,0 +1,10 @@
-- Standard I/O Streams
with Ada.Integer_Text_Io;
procedure APlusB is
A, B : Integer;
begin
Ada.Integer_Text_Io.Get (Item => A);
Ada.Integer_Text_Io.Get (Item => B);
Ada.Integer_Text_Io.Put (A+B);
end APlusB;

12
Task/A+B/Ada/a+b-2.ada Normal file
View file

@ -0,0 +1,12 @@
with Ada.Text_IO;
procedure A_Plus_B is
type Small_Integers is range -2_000 .. +2_000;
subtype Input_Values is Small_Integers range -1_000 .. +1_000;
package IO is new Ada.Text_IO.Integer_IO (Num => Small_Integers);
A, B : Input_Values;
begin
IO.Get (A);
IO.Get (B);
IO.Put (A + B, Width => 4, Base => 10);
end A_Plus_B;

View file

@ -0,0 +1,4 @@
(: Standard input-output streams :)
use std, array
Cfunc scanf "%d%d" (&val int a) (&val int b)
printf "%d\n" (a + b)

View file

@ -0,0 +1,10 @@
(: Input file : input.txt :)
(: Output file: output.txt :)
use std, array
let in = fopen "input.txt" "r"
let out = fopen "output.txt" "w"
let int x, y.
Cfunc fscanf in "%d%d" (&x) (&y) (:fscanf not yet defined in std.arg:)
fprintf out "%d\n" (x+y)
fclose in
fclose out

View file

@ -0,0 +1,3 @@
InputBox, input , A+B, Two integer numbers`, separated by space.
StringSplit, output, input, %A_Space%
msgbox, % output1 . "+" . output2 "=" output1+output2

View file

@ -0,0 +1,7 @@
;AutoIt Version: 3.2.10.0
$num = "45 54"
consolewrite ("Sum of " & $num & " is: " & sum($num))
Func sum($numbers)
$numm = StringSplit($numbers," ")
Return $numm[1]+$numm[$numm[0]]
EndFunc

16
Task/A+B/BASIC/a+b.bas Normal file
View file

@ -0,0 +1,16 @@
DEFINT A-Z
tryagain:
backhere = CSRLIN
INPUT "", i$
i$ = LTRIM$(RTRIM$(i$))
where = INSTR(i$, " ")
IF where THEN
a = VAL(LEFT$(i$, where - 1))
b = VAL(MID$(i$, where + 1))
c = a + b
LOCATE backhere, LEN(i$) + 1
PRINT c
ELSE
GOTO tryagain
END IF

1
Task/A+B/Befunge/a+b.bf Normal file
View file

@ -0,0 +1 @@
&&+.@

9
Task/A+B/C/a+b-1.c Normal file
View file

@ -0,0 +1,9 @@
// Standard input-output streams
#include <stdio.h>
int main()
{
int a, b;
scanf("%d%d", &a, &b);
printf("%d\n", a + b);
return 0;
}

12
Task/A+B/C/a+b-2.c Normal file
View file

@ -0,0 +1,12 @@
// Input file: input.txt
// Output file: output.txt
#include <stdio.h>
int main()
{
freopen("input.txt", "rt", stdin);
freopen("output.txt", "wt", stdout);
int a, b;
scanf("%d%d", &a, &b);
printf("%d\n", a + b);
return 0;
}

View file

@ -0,0 +1,4 @@
(println (+ (Integer/parseInt (read-line)) (Integer/parseInt (read-line))))
3
4
=>7

View file

@ -0,0 +1,3 @@
(eval (read-string (str "(+ " (read-line) " )") ))
3 3
6

View file

@ -0,0 +1,14 @@
<html>
<script type="text/javascript" src="http://jashkenas.github.com/coffee-script/extras/coffee-script.js"></script>
<script type="text/coffeescript">
a = window.prompt 'enter A number', ''
b = window.prompt 'enter B number', ''
document.getElementById('input').innerHTML = a + ' ' + b
sum = parseInt(a) + parseInt(b)
document.getElementById('output').innerHTML = sum
</script>
<body>
<div id='input'></div>
<div id='output'></div>
</body>
</html>

13
Task/A+B/Eiffel/a+b.e Normal file
View file

@ -0,0 +1,13 @@
class
APPLICATION
inherit
ARGUMENTS
create
make
feature {NONE} -- Initialization
make
-- Run application.
do
print(argument(1).to_integer + argument(2).to_integer)
end
end

10
Task/A+B/Erlang/a+b.erl Normal file
View file

@ -0,0 +1,10 @@
-module(aplusb).
-export([start/0]).
start() ->
case io:fread("","~d~d") of
eof -> ok;
{ok, [A,B]} ->
io:format("~w~n",[A+B]),
start()
end.

1
Task/A+B/Forth/a+b.fth Normal file
View file

@ -0,0 +1 @@
pad dup 80 accept evaluate + .

10
Task/A+B/Fortran/a+b.f Normal file
View file

@ -0,0 +1,10 @@
program a_plus_b
implicit none
integer :: a
integer :: b
read (*, *) a, b
write (*, '(i0)') a + b
end program a_plus_b

9
Task/A+B/Go/a+b.go Normal file
View file

@ -0,0 +1,9 @@
package main
import "fmt"
func main() {
var a, b int
fmt.Scanf("%d %d", &a, &b)
fmt.Printf("%d\n", a+b)
}

1
Task/A+B/Haskell/a+b.hs Normal file
View file

@ -0,0 +1 @@
main = getLine >>= print . sum . map read . words

8
Task/A+B/Java/a+b-1.java Normal file
View file

@ -0,0 +1,8 @@
import java.util.*;
public class Sum2 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in); // Standard input
System.out.println(in.nextInt() + in.nextInt()); // Standard output
}
}

27
Task/A+B/Java/a+b-2.java Normal file
View file

@ -0,0 +1,27 @@
import java.io.*;
import java.util.*;
public class SumDif {
StreamTokenizer in;
PrintWriter out;
public static void main(String[] args) throws IOException {
new SumDif().run();
}
private int nextInt() throws IOException {
in.nextToken();
return (int)in.nval;
}
public void run() throws IOException {
in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); // Standard input
out = new PrintWriter(new OutputStreamWriter(System.out)); // Standard output
solve();
out.flush();
}
private void solve() throws IOException {
out.println(nextInt() + nextInt());
}
}

19
Task/A+B/Java/a+b-3.java Normal file
View file

@ -0,0 +1,19 @@
import java.io.*;
public class AplusB {
public static void main(String[] args) {
try {
StreamTokenizer in = new StreamTokenizer(new FileReader("input.txt"));
in.nextToken();
int a = (int) in.nval;
in.nextToken();
int b = (int) in.nval;
FileWriter outFile = new FileWriter("output.txt");
outFile.write(Integer.toString(a + b));
outFile.close();
}
catch (IOException e) {
System.out.println("IO error");
}
}
}

View file

@ -0,0 +1,14 @@
<html>
<body>
<div id='input'></div>
<div id='output'></div>
<script type='text/javascript'>
var a = window.prompt('enter A number', '');
var b = window.prompt('enter B number', '');
document.getElementById('input').innerHTML = a + ' ' + b;
var sum = Number(a) + Number(b);
document.getElementById('output').innerHTML = sum;
</script>
</body>
</html>

View file

@ -0,0 +1,10 @@
process.openStdin().on (
'data',
function (line) {
var xs = String(line).match(/^\s*(\d+)\s+(\d+)\s*/)
console.log (
xs ? Number(xs[1]) + Number(xs[2]) : 'usage: <integer> <integer>'
)
process.exit()
}
)

2
Task/A+B/Lua/a+b.lua Normal file
View file

@ -0,0 +1,2 @@
a,b = io.read("*number", "*number")
print(a+b)

2
Task/A+B/PHP/a+b-1.php Normal file
View file

@ -0,0 +1,2 @@
fscanf(STDIN, "%d %d\n", $a, $b); //Reads 2 numbers from STDIN
echo ($a + $b) . "\n";

7
Task/A+B/PHP/a+b-2.php Normal file
View file

@ -0,0 +1,7 @@
$in = fopen("input.dat", "r");
fscanf($in, "%d %d\n", $a, $b); //Reads 2 numbers from file $in
fclose($in);
$out = fopen("output.dat", "w");
fwrite($out, ($a + $b) . "\n");
fclose($out);

2
Task/A+B/Perl/a+b.pl Normal file
View file

@ -0,0 +1,2 @@
my ($a,$b) = split(/\D+/,<STDIN>);
print "$a $b " . ($a + $b) . "\n";

3
Task/A+B/PicoLisp/a+b.l Normal file
View file

@ -0,0 +1,3 @@
(+ (read) (read))
3 4
-> 7

View file

@ -0,0 +1,7 @@
plus :-
read_line_to_codes(user_input,X),
atom_codes(A, X),
atomic_list_concat(L, ' ', A),
maplist(atom_number, L, LN),
sumlist(LN, N),
write(N).

View file

@ -0,0 +1,4 @@
?- plus.
|: 4 5
9
true.

4
Task/A+B/Python/a+b-1.py Normal file
View file

@ -0,0 +1,4 @@
try: raw_input
except: raw_input = input
print(sum(int(x) for x in raw_input().split()))

4
Task/A+B/Python/a+b-2.py Normal file
View file

@ -0,0 +1,4 @@
a = int(raw_input("Enter integer 1: "))
b = int(raw_input("Enter integer 2: "))
print a + b

1
Task/A+B/R/a+b.r Normal file
View file

@ -0,0 +1 @@
sum(scan("", numeric(0), 2))

2
Task/A+B/REXX/a+b-1.rexx Normal file
View file

@ -0,0 +1,2 @@
parse pull a b
say a+b

2
Task/A+B/REXX/a+b-2.rexx Normal file
View file

@ -0,0 +1,2 @@
parse pull a b
say (a+b)/1 /*dividing by 1 normalizes the REXX number.*/

4
Task/A+B/REXX/a+b-3.rexx Normal file
View file

@ -0,0 +1,4 @@
numeric digits 300
parse pull a b
z=(a+b)/1
say z

9
Task/A+B/REXX/a+b-4.rexx Normal file
View file

@ -0,0 +1,9 @@
numeric digits 1000 /*just in case the user gets ka-razy. */
say 'enter some numbers to be summed:'
parse pull y
many=words(y)
sum=0
do j=1 for many
sum=sum+word(y,j)
end
say 'sum of' many "numbers = " sum/1

View file

@ -0,0 +1,2 @@
#lang racket
(+ (read) (read))

View file

@ -0,0 +1,6 @@
#lang racket
(define a (read))
(unless (number? a) (error 'a+b "number" a))
(define b (read))
(unless (number? b) (error 'a+b "number" b))
(displayln (+ a b))

1
Task/A+B/Ruby/a+b-1.rb Normal file
View file

@ -0,0 +1 @@
puts gets.split.map{|x| x.to_i}.inject{|sum, x| sum + x}

1
Task/A+B/Ruby/a+b-2.rb Normal file
View file

@ -0,0 +1 @@
puts gets.split.map(&:to_i).inject(&:+)

1
Task/A+B/Scala/a+b.scala Normal file
View file

@ -0,0 +1 @@
println(readLine() split " " take 2 map (_.toInt) sum)

3
Task/A+B/Scheme/a+b.ss Normal file
View file

@ -0,0 +1,3 @@
(let* ((x (read))
(y (read)))
(write (+ x y)))

View file

@ -0,0 +1,30 @@
'From Squeak3.7 of ''4 September 2004'' [latest update: #5989] on 8 August 2011 at 3:50:55 pm'!
Object subclass: #ABTask
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'rosettacode'!
"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!
ABTask class
instanceVariableNames: ''!
!ABTask class methodsFor: 'demo'!
parseInteger: inputStream
^ Integer readFrom: inputStream skipSeparators! !
!ABTask class methodsFor: 'demo'!
sum: inputStream
^ (self parseInteger: inputStream)
+ (self parseInteger: inputStream)! !
!ABTask class methodsFor: 'demo'!
test2Plus2
^ self
sum: (ReadStream on: '2 2')! !
!ABTask class methodsFor: 'demo'!
test3Plus2
^ self
sum: (ReadStream on: '3 2')! !

View file

@ -0,0 +1,19 @@
|task|
task := [:inStream :outStream |
|processLine|
processLine :=
[
|a b|
a := Integer readFrom: inStream.
b := Integer readFrom: inStream.
"is validation part of the task?"
self assert:( a between:-1000 and: 1000).
self assert:( b between:-1000 and: 1000).
outStream print (a+b); cr.
].
[ inStream atEnd ] whileFalse:processLine.
].
task value: ( 'dataIn.txt' asFilename readStream) value:Transcript.

View file

@ -0,0 +1 @@
task value: Stdin value: Stdout.

2
Task/A+B/Tcl/a+b-1.tcl Normal file
View file

@ -0,0 +1,2 @@
scan [gets stdin] "%d %d" x y
puts [expr {$x + $y}]

1
Task/A+B/Tcl/a+b-2.tcl Normal file
View file

@ -0,0 +1 @@
puts [tcl::mathop::+ {*}[gets stdin]]

6
Task/A+B/Tcl/a+b-3.tcl Normal file
View file

@ -0,0 +1,6 @@
set in [open "input.txt"]
set out [open "output.txt" w]
scan [gets $in] "%d %d" x y
puts $out [expr {$x + $y}]
close $in
close $out

View file

@ -0,0 +1,11 @@
'''Abstract type''' is a type without instances or without definition.
For example in [[object-oriented programming]] using some languages, abstract types can be partial implementations of other types, which are to be derived there-from. An abstract type may provide implementation of some operations and/or components. Abstract types without any implementation are called '''interfaces'''. In the languages that do not support multiple [[inheritance]] ([[Ada]], [[Java]]), classes can, nonetheless, inherit from multiple interfaces. The languages with multiple inheritance (like [[C++]]) usually make no distinction between partially implementable abstract types and interfaces. Because the abstract type's implementation is incomplete, [[object-oriented programming | OO]] languages normally prevent instantiation from them (instantiation must derived from one of their descendant classes).
The term '''abstract datatype''' also may denote a type, with an implementation provided by the programmer rather than directly by the language (a '''built-in''' or an inferred type). Here the word ''abstract'' means that the implementation is abstracted away, irrelevant for the user of the type. Such implementation can and should be hidden if the language supports separation of implementation and specification. This hides complexity while allowing the implementation to change without repercussions on the usage. The corresponding software design practice is said to follow the [[wp:Information_hiding|information hiding principle]].
It is important not to confuse this ''abstractness'' (of implementation) with one of the '''abstract type'''. The latter is abstract in the sense that the set of its values is empty. In the sense of implementation abstracted away, all user-defined types are abstract.
In some languages, like for example in Objective Caml which is strongly statically typed, it is also possible to have '''abstract types''' that are not OO related and are not an abstractness too. These are ''pure abstract types'' without any definition even in the implementation and can be used for example for the type algebra, or for some consistence of the type inference. For example in this area, an abstract type can be used as a phantom type to augment another type as its parameter. <!-- An OCaml Guru would explain this better than me, a poor beginner... -->
'''Task''': show how an abstract type can be declared in the language. If the language makes a distinction between interfaces and partially implemented types illustrate both.

View file

@ -0,0 +1,5 @@
---
category:
- Object oriented
- Type System
note: Basic language learning

View file

@ -0,0 +1,13 @@
class abs definition abstract.
public section.
methods method1 abstract importing iv_value type f exporting ev_ret type i.
protected section.
methods method2 abstract importing iv_name type string exporting ev_ret type i.
methods add importing iv_a type i iv_b type i exporting ev_ret type i.
endclass.
class abs implementation.
method add.
ev_ret = iv_a + iv_b.
endmethod.
endclass.

View file

@ -0,0 +1,5 @@
interface inter.
methods: method1 importing iv_value type f exporting ev_ret type i,
method2 importing iv_name type string exporting ev_ret type i,
add importing iv_a type i iv_b type i exporting ev_ret type i.
endinterface.

View file

@ -0,0 +1,8 @@
package
{
public interface IInterface
{
function method1():void;
function method2(arg1:Array, arg2:Boolean):uint;
}
}

View file

@ -0,0 +1,3 @@
type Queue is limited interface;
procedure Enqueue (Lounge : in out Queue; Item : in out Element) is abstract;
procedure Dequeue (Lounge : in out Queue; Item : in out Element) is abstract;

View file

@ -0,0 +1,2 @@
type Scheduler is task interface;
procedure Plan (Manager : in out Scheduler; Activity : in out Job) is abstract;

View file

@ -0,0 +1,10 @@
with Ada.Finalization;
...
type Node is abstract new Ada.Finalization.Limited_Controlled and Queue with record
Previous : not null access Node'Class := Node'Unchecked_Access;
Next : not null access Node'Class := Node'Unchecked_Access;
end record;
overriding procedure Finalize (X : in out Node); -- Removes the node from its list if any
overriding procedure Dequeue (Lounge : in out Node; Item : in out Element);
overriding procedure Enqueue (Lounge : in out Node; Item : in out Element);
procedure Process (X : in out Node) is abstract; -- To be implemented

View file

@ -0,0 +1,53 @@
module AbstractInterfaceExample where
open import Function
open import Data.Bool
open import Data.String
-- * One-parameter interface for the type `a' with only one method.
record VoiceInterface (a : Set) : Set where
constructor voice-interface
field say-method-of : a String
open VoiceInterface
-- * An overloaded method.
say : {a : Set} _ : VoiceInterface a a String
say instance = say-method-of instance
-- * Some data types.
data Cat : Set where
cat : Bool Cat
crazy! = true
plain-cat = false
-- | This cat is crazy?
crazy? : Cat Bool
crazy? (cat x) = x
-- | A 'plain' dog.
data Dog : Set where
dog : Dog
-- * Implementation of the interface (and method).
instance-for-cat : VoiceInterface Cat
instance-for-cat = voice-interface case where
case : Cat String
case x with crazy? x
... | true = "meeeoooowwwww!!!"
... | false = "meow!"
instance-for-dog : VoiceInterface Dog
instance-for-dog = voice-interface $ const "woof!"
-- * and then:
--
-- say dog => "woof!"
-- say (cat crazy!) => "meeeoooowwwww!!!"
-- say (cat plain-cat) => "meow!"
--

View file

@ -0,0 +1,5 @@
class Abs {
public function method1...
public function method2...
}

View file

@ -0,0 +1,5 @@
interface Inter {
function isFatal : integer
function operate (para : integer = 0)
operator -> (stream, isout)
}

View file

@ -0,0 +1,38 @@
use std
(: abstract class :)
class Abs
text name
AbsIface iface
class AbsIface
function(Abs)(int)->int method
let Abs_Iface = Cdata AbsIface@ {.method = nil}
.: new Abs :. -> Abs {let a = new(Abs); a.iface = Abs_Iface; a}
=: <Abs self>.method <int i> := -> int
(self.iface.method is nil) ? 0 , (call self.iface.method with self i)
(: implementation :)
class Sub <- Abs { int value }
let Sub_Iface = Cdata AbsIface@ {.method = (code of (nil the Sub).method 0)}
.: new Sub (<int value = -1>) :. -> Sub
let s = new (Sub)
s.iface = Sub_Iface
s.value = value
s
.: <Sub this>.method <int i> :. -> int {this.value + i}
(: example use :)
.:foobar<Abs a>:. {print a.method 12 ; del a}
foobar (new Sub 34) (: prints 46 :)
foobar (new Sub) (: prints 11 :)
foobar (new Abs) (: prints 0 :)

View file

@ -0,0 +1,28 @@
color(r, g, b){
static color
If !color
color := Object("base", Object("R", r, "G", g, "B", b
,"GetRGB", "Color_GetRGB"))
return Object("base", Color)
}
Color_GetRGB(clr) {
return "not implemented"
}
waterColor(r, g, b){
static waterColor
If !waterColor
waterColor := Object("base", color(r, g, b),"GetRGB", "WaterColor_GetRGB")
return Object("base", WaterColor)
}
WaterColor_GetRGB(clr){
return clr.R << 16 | clr.G << 8 | clr.B
}
test:
blue := color(0, 0, 255)
msgbox % blue.GetRGB() ; displays "not implemented"
blue := waterColor(0, 0, 255)
msgbox % blue.GetRGB() ; displays 255
return

View file

@ -0,0 +1,33 @@
#ifndef INTERFACE_ABS
#define INTERFACE_ABS
typedef struct sAbstractCls *AbsCls;
typedef struct sAbstractMethods {
int (*method1)(AbsCls c, int a);
const char *(*method2)(AbsCls c, int b);
void (*method3)(AbsCls c, double d);
} *AbstractMethods, sAbsMethods;
struct sAbstractCls {
AbstractMethods klass;
void *instData;
};
#define ABSTRACT_METHODS( cName, m1, m2, m3 ) \
static sAbsMethods cName ## _Iface = { &m1, &m2, &m3 }; \
AbsCls cName ## _Instance( void *clInst) { \
AbsCls ac = malloc(sizeof(struct sAbstractCls)); \
if (ac) { \
ac->klass = &cName ## _Iface; \
ac->instData = clInst; \
}\
return ac; }
#define Abs_Method1( c, a) (c)->klass->method1(c, a)
#define Abs_Method2( c, b) (c)->klass->method2(c, b)
#define Abs_Method3( c, d) (c)->klass->method3(c, d)
#define Abs_Free(c) \
do { if (c) { free((c)->instData); free(c); } } while(0);
#endif

View file

@ -0,0 +1,9 @@
#ifndef SILLY_H
#define SILLY_H
#include intefaceAbs.h
typedef struct sillyStruct *Silly;
extern Silly NewSilly( double, const char *);
extern AbsCls Silly_Instance(void *);
#endif

View file

@ -0,0 +1,42 @@
#include "silly.h"
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
struct sillyStruct {
double v1;
char str[32];
};
Silly NewSilly(double vInit, const char *strInit)
{
Silly sily = malloc(sizeof( struct sillyStruct ));
sily->v1 = vInit;
sily->str[0] = '\0';
strncat(sily->str, strInit, 31);
return sily;
}
static
int MyMethod1( AbsCls c, int a)
{
Silly s = (Silly)(c->instData);
return a+strlen(s->str);
}
static
const char *MyMethod2(AbsCls c, int b)
{
Silly s = (Silly)(c->instData);
sprintf(s->str, "%d", b);
return s->str;
}
static
void MyMethod3(AbsCls c, double d)
{
Silly s = (Silly)(c->instData);
printf("InMyMethod3, %f\n",s->v1 * d);
}
ABSTRACT_METHODS( Silly, MyMethod1, MyMethod2, MyMethod3)

View file

@ -0,0 +1,13 @@
#include <stdio.h>
#include "silly.h"
int main()
{
AbsCls abster = Silly_Instance(NewSilly( 10.1, "Green Tomato"));
printf("AbsMethod1: %d\n", Abs_Method1(abster, 5));
printf("AbsMethod2: %s\n", Abs_Method2(abster, 4));
Abs_Method3(abster, 21.55);
Abs_Free(abster);
return 0;
}

View file

@ -0,0 +1 @@
(defprotocol Foo (foo [this]))

View file

@ -0,0 +1,17 @@
deferred class
AN_ABSTRACT_CLASS
feature
a_deferred_feature
-- a feature whose implementation is left to a descendent
deferred
end
an_effective_feature: STRING
-- deferred (abstract) classes may still include effective features
do
Result := "I am implemented!"
end
end

View file

@ -0,0 +1,25 @@
include 4pp/lib/foos.4pp
:: X()
class
method: method1
method: method2
end-class {
:method { ." Method 1 in X" cr } ; defines method1
}
;
:: Y()
extends X()
end-extends {
:method { ." Method 2 in Y" cr } ; defines method2
}
;
: Main
static Y() y
y => method1
y => method2
;
Main

View file

@ -0,0 +1,5 @@
interface {
Method1(value float64) int
SetName(name string)
GetName() string
}

View file

@ -0,0 +1,3 @@
class Eq a where
(==) :: a -> a -> Bool
(/=) :: a -> a -> Bool

View file

@ -0,0 +1,5 @@
class Eq a where
(==) :: a -> a -> Bool
(/=) :: a -> a -> Bool
x /= y = not (x == y)
x == y = not (x /= y)

View file

@ -0,0 +1,2 @@
func :: (Eq a) => a -> Bool
func x = x == x

View file

@ -0,0 +1 @@
data Foo = Foo {x :: Integer, str :: String}

View file

@ -0,0 +1,3 @@
instance Eq Foo where
(Foo x1 str1) == (Foo x2 str2) =
(x1 == x2) && (str1 == str2)

View file

@ -0,0 +1,3 @@
class abstraction()
abstract method compare(l,r) # generates runerr(700, "method compare()")
end

View file

@ -0,0 +1,7 @@
public abstract class Abs {
abstract public int method1(double value);
abstract protected int method2(String name);
int add(int a, int b){
return a+b;
}
}

View file

@ -0,0 +1,5 @@
public interface Inter {
int method1(double value);
int method2(String name);
int add(int a, int b);
}

View file

@ -0,0 +1,34 @@
BaseClass = {}
function class ( baseClass )
local new_class = {}
local class_mt = { __index = new_class }
function new_class:new()
local newinst = {}
setmetatable( newinst, class_mt )
return newinst
end
if not baseClass then baseClass = BaseClass end
setmetatable( new_class, { __index = baseClass } )
return new_class
end
function abstractClass ( self )
local new_class = {}
local class_mt = { __index = new_class }
function new_class:new()
error("Abstract classes cannot be instantiated")
end
if not baseClass then baseClass = BaseClass end
setmetatable( new_class, { __index = baseClass } )
return new_class
end
BaseClass.class = class
BaseClass.abstractClass = abstractClass

View file

@ -0,0 +1,8 @@
A = class() -- New class A inherits BaseClass by default
AA = A:class() -- New class AA inherits from existing class A
B = abstractClass() -- New abstract class B
BB = B:class() -- BB is not abstract
A:new() -- Okay: New class instance
AA:new() -- Okay: New class instance
B:new() -- Error: B is abstract
BB:new() -- Okay: BB is not abstract

View file

@ -0,0 +1,7 @@
abstract class Abs {
abstract public function method1($value);
abstract protected function method2($name);
function add($a, $b){
return a + b;
}
}

View file

@ -0,0 +1,5 @@
interface Inter {
public function method1($value);
public function method2($name);
public function add($a, $b);
}

View file

@ -0,0 +1,14 @@
package AbstractFoo;
use strict;
sub frob { die "abstract" }
sub baz { die "abstract" }
sub frob_the_baz {
my $self = shift;
$self->frob($self->baz());
}
1;

View file

@ -0,0 +1,13 @@
package AbstractFoo;
use strict;
sub frob { ... }
sub baz { ... }
sub frob_the_baz {
my $self = shift;
$self->frob($self->baz());
}
1;

View file

@ -0,0 +1,12 @@
package AbstractFoo;
use Moose::Role;
requires qw/frob baz/;
sub frob_the_baz {
my $self = shift;
$self->frob($self->baz());
}
1;

View file

@ -0,0 +1,12 @@
package AbstractFoo;
use Role::Tiny;
requires qw/frob baz/;
sub frob_the_baz {
my $self = shift;
$self->frob($self->baz());
}
1;

View file

@ -0,0 +1,11 @@
# In PicoLisp there is no formal difference between abstract and concrete classes.
# There is just a naming convention where abstract classes start with a
# lower-case character after the '+' (the naming convention for classes).
# This tells the programmer that this class has not enough methods
# defined to survive on its own.
(class +abstractClass)
(dm someMethod> ()
(foo)
(bar) )

View file

@ -0,0 +1,13 @@
class BaseQueue(object):
"""Abstract/Virtual Class
"""
def __init__(self):
self.contents = list()
raise NotImplementedError
def Enqueue(self, item):
raise NotImplementedError
def Dequeue(self):
raise NotImplementedError
def Print_Contents(self):
for i in self.contents:
print i,

View file

@ -0,0 +1,21 @@
from abc import ABCMeta, abstractmethod
class BaseQueue():
"""Abstract Class
"""
__metaclass__ = ABCMeta
def __init__(self):
self.contents = list()
@abstractmethod
def Enqueue(self, item):
pass
@abstractmethod
def Dequeue(self):
pass
def Print_Contents(self):
for i in self.contents:
print i,

View file

@ -0,0 +1,13 @@
#lang racket
(define animal-interface (interface () say))
(define cat% (class* object% (animal-interface) (super-new))) ;; error
(define cat% (class* object% (animal-interface)
(super-new)
(define/public (say)
(display "meeeeew!"))))
(define tom (new cat%))
(send tom say)

View file

@ -0,0 +1,17 @@
require 'abstraction'
class AbstractQueue
abstract
def enqueue(object)
raise NotImplementedError
end
def dequeue
raise NotImplementedError
end
end
class ConcreteQueue < AbstractQueue
def enqueue(object)
puts "enqueue #{object.inspect}"
end
end

View file

@ -0,0 +1,10 @@
abstract class X {
type A
var B: A
val C: A
def D(a: A): A
}
trait Y {
val x: X
}

Some files were not shown because too many files have changed in this diff Show more