mirror of
				https://github.com/KevinMidboe/linguist.git
				synced 2025-10-29 17:50:22 +00:00 
			
		
		
		
	This change includes a brief (non-sensical) sample program I wrote to illustrate many of Cool's language constructs, as well as a simple rule to distinguish Cool files from Common Lisp or OpenCL (it has a line that starts with the word 'class'). Further, it includes a second example program adapted from an example contained in the Cool distribution (list.cl), which contains a few further language constructs and captures the style of a Cool program.
		
			
				
	
	
		
			27 lines
		
	
	
		
			581 B
		
	
	
	
		
			Common Lisp
		
	
	
	
	
	
			
		
		
	
	
			27 lines
		
	
	
		
			581 B
		
	
	
	
		
			Common Lisp
		
	
	
	
	
	
(* This simple example of a list class is adapted from an example in the
 | 
						|
   Cool distribution. *)
 | 
						|
 | 
						|
class List {
 | 
						|
   isNil() : Bool { true };
 | 
						|
   head()  : Int { { abort(); 0; } };
 | 
						|
   tail()  : List { { abort(); self; } };
 | 
						|
   cons(i : Int) : List {
 | 
						|
      (new Cons).init(i, self)
 | 
						|
   };
 | 
						|
};
 | 
						|
 | 
						|
class Cons inherits List {
 | 
						|
   car : Int;	-- The element in this list cell
 | 
						|
   cdr : List;	-- The rest of the list
 | 
						|
   isNil() : Bool { false };
 | 
						|
   head()  : Int { car };
 | 
						|
   tail()  : List { cdr };
 | 
						|
   init(i : Int, rest : List) : List {
 | 
						|
      {
 | 
						|
	 car <- i;
 | 
						|
	 cdr <- rest;
 | 
						|
	 self;
 | 
						|
      }
 | 
						|
   };
 | 
						|
};
 |