added t/insta-2.hcl
This commit is contained in:
		
							
								
								
									
										32
									
								
								lang.txt
									
									
									
									
									
								
							
							
						
						
									
										32
									
								
								lang.txt
									
									
									
									
									
								
							| @ -85,9 +85,41 @@ send the message dump to the object pointed to by x with arguments 1, 2, 3. | |||||||
| ## method types | ## method types | ||||||
|  |  | ||||||
| - class method | - class method | ||||||
|  |  | ||||||
|  |  | ||||||
| - class instantiation method | - class instantiation method | ||||||
|  |  | ||||||
|  | 	(defclass P | ||||||
|  | 		| x y | | ||||||
|  | 		(defun ::* new () | ||||||
|  | 			(set x 1)	 | ||||||
|  | 			(set y 1)	 | ||||||
|  | 			(return self) | ||||||
|  | 		) | ||||||
|  | 		(defun get-x() x) | ||||||
|  | 		(defun get-y() y) | ||||||
|  | 	) | ||||||
|  | 	(defclass X ::: P | ||||||
|  | 		| x y | | ||||||
|  | 		(defun ::* new (a b) | ||||||
|  | 			(:super new) | ||||||
|  | 			x = a | ||||||
|  | 			y = b | ||||||
|  | 			(return self) | ||||||
|  | 		) | ||||||
|  | 		(defun get-xx() x) | ||||||
|  | 		(defun get-yy() y) | ||||||
|  | 	) | ||||||
|  |  | ||||||
|  | 	(set t (:X new 10 20)) ;t is an instance of X | ||||||
|  | 	(printf "%d %d %d %d\n" (:t get-x) (:t get-y) (:t get-xx) (:t get-yy)) ; must print 1 1 10 20 | ||||||
|  | 	(:t new 100 300)  ;the x, y in the X part get reset to 100 and 300. doesn't create a new instance | ||||||
|  | 	(printf "%d %d %d %d\n" (:t get-x) (:t get-y) (:t get-xx) (:t get-yy)) ; must print 1 1 100 300 | ||||||
|  |  | ||||||
| - instance method | - instance method | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
| ## dynamic dispatching by method name | ## dynamic dispatching by method name | ||||||
| 	(defclass X | 	(defclass X | ||||||
| 		(defun t1 (x) (printf "t1 = %d\n" (+ x x x))) | 		(defun t1 (x) (printf "t1 = %d\n" (+ x x x))) | ||||||
|  | |||||||
| @ -2,6 +2,7 @@ AUTOMAKE_OPTIONS = nostdinc | |||||||
|  |  | ||||||
| check_SCRIPTS = \ | check_SCRIPTS = \ | ||||||
| 	insta-01.hcl \ | 	insta-01.hcl \ | ||||||
|  | 	insta-02.hcl \ | ||||||
| 	ret-01.hcl \ | 	ret-01.hcl \ | ||||||
| 	retvar-01.hcl | 	retvar-01.hcl | ||||||
|  |  | ||||||
|  | |||||||
| @ -463,6 +463,7 @@ top_srcdir = @top_srcdir@ | |||||||
| AUTOMAKE_OPTIONS = nostdinc | AUTOMAKE_OPTIONS = nostdinc | ||||||
| check_SCRIPTS = \ | check_SCRIPTS = \ | ||||||
| 	insta-01.hcl \ | 	insta-01.hcl \ | ||||||
|  | 	insta-02.hcl \ | ||||||
| 	ret-01.hcl \ | 	ret-01.hcl \ | ||||||
| 	retvar-01.hcl | 	retvar-01.hcl | ||||||
|  |  | ||||||
|  | |||||||
							
								
								
									
										13
									
								
								t/insta-02.hcl
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								t/insta-02.hcl
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,13 @@ | |||||||
|  | (set t  | ||||||
|  | 	(defclass X | ||||||
|  | 		| x |  | ||||||
|  | 		(defun ::* make() (set x 1234) self) | ||||||
|  | 		(defun get-x() x) | ||||||
|  | 	) | ||||||
|  | ) | ||||||
|  | (if (nqv? t X) (printf "ERROR: t must point to X\n")) | ||||||
|  | (printf "OK: t points to X\n") | ||||||
|  |  | ||||||
|  | (set t (:(:t make) get-x)) | ||||||
|  | (if (nqv? t 1234) (printf "ERROR: t must be 1234\n")) | ||||||
|  | (printf "OK: t is %d\n" t) | ||||||
		Reference in New Issue
	
	Block a user