Creating A Simple Defsetf
This page was created by/for creating simple Defsetf based functions/macros. This will describe how to accomplish this task, as well as a table of what has been done already, what is not finished, and what has yet to be done.
To make a basic defsetf (Please note: Italicized FUNCTION-NAME will need to be replaced by the corresponding name of the function being added to setf):
- Setf.lsp
- Check out setf.lsp from Perforce
- Add the following line in setf.lsp (Please note: there is currently a section with defsetf based functions. Look for FILL-POINTER):
- (defsetf FUNCTION-NAME system::%set-FUNCTION-NAME)
- The above allows setf to now recognize the new function name when used inside setf.
- CommonLispFunctions.java
- Check out CommonLispFunction? .java
- Add the following line in CommonLispFunctions? .java (Please note: there is currently a section here as well, located near the bottom. Look for SetChar? , SetSchar? , SetSvref? , or SetAref? ):
- public final Function PercentFUNCTION-NAME = lisp.system.function.FUNCTION-NAME.FUNCTION;
- An example FUNCTION-NAME for the above would be: SetChar? , SetSchar? , SetSvref? , or SetArev? .
- The above will be underlined in red for now, as that particular class has not yet been created in the system directory.
- Creating the new "Setting" function
- The file that will do the actual setting must now be created from within Java. The file should be located in the following directory: "java/lisp/system/function". There is no particular way to describe every single function needed to be implemented. However, I have provided (as seen below) an example. This is SetSvref? .java. This function takes a Simple-Vector and sets a particular index to whatever the new index is. DO NOT attempt to just copy this code and expect it to work. The particular function to be implemented should be taken into account.
- Check to make sure it works (YOU MUST DO THIS!!!!!! NEVER ASSUME THAT IT WILL ALWAYS JUST WORK.)
- Submit to Perforce
/*
Copyright (c) 2006 College of Charleston, Charleston, SC, USA
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/*
* SetSvref.java
*
* Created on March 29, 2010, 3:19 PM
*
* @author scnelson
*
*/
package lisp.system.function;
/**
*
* @author scnelson
*/
import lisp.common.exceptions.FunctionException;
import lisp.common.function.FunctionBaseClass;
import lisp.common.type.Boolean;
import lisp.common.type.Integer;
import lisp.common.type.List;
import lisp.common.type.Package;
import lisp.common.type.Symbol;
import lisp.common.type.T;
import lisp.common.type.SimpleVector;
import lisp.extensions.type.Function3;
/**
* Singleton class representing a utility function to set a key/value pair
* in a hash table.
*
* @author Cody Nelson
*/
public class SetSvref extends FunctionBaseClass implements Function3 { public static final SetSvref FUNCTION = new SetSvref();
public static final Symbol SYMBOL = Package.System.intern("%SET-SVREF")[0]; static { SYMBOL.setFunction(FUNCTION); } private SetSvref() { }
/**
* General method for function call to GETHASH.
*
* @param argsList {@link lisp.common.type.List List} of arguments passed in * by the Lisp compiler.
* @return Previous value assoicated with the key or
* {@link lisp.common.type.Boolean#NIL Boolean.NIL} if there was no value * associated with the key.
*/
public Object apply(List argsList) { // the order is .. new-value key hashtable others ...
return funcall(argsList.getCar(), argsList.rest().getCar(), argsList.rest().rest().getCar());
}
/**
* Associates a value with a key in the given hash table.
*
* @param arg1 The key, which should be an Character.
* @param arg2 The value, which should be an instance of {@link lisp.common.type.T T}. * @param arg3 {@link lisp.common.type.HashTable HashTable} in which to store the key/value * pair.
* @return Previous value assoicated with the key or
* {@link lisp.common.type.Boolean#NIL Boolean.NIL} if there was no value * associated with the key.
*/
public Object funcall(Object arg1, Object arg2, Object arg3) { if (!(arg1 instanceof SimpleVector)){ throw new FunctionException(arg1 + " is not of type SIMPLE-VECTOR",
new IllegalArgumentException());
}
SimpleVector theSimpleVector = (SimpleVector)arg1;
Integer index = (Integer)arg2;
Object theObject = (Object)arg3;
theSimpleVector.set(index.intValue(), theObject);
return arg1;
}
}
--
CodyNelson - 30 Mar 2010
| Functions-used-in-Setf |
Author |
Coded |
Completed |
| List-based |
| C***R |
---------- |
Yes |
Yes |
| FIRST - TENTH |
---------- |
Yes |
Yes |
| NTH |
---------- |
Yes |
Yes |
| REST |
---------- |
Yes |
Yes |
| Sequence-based |
| ELT |
---------- |
Yes |
Yes |
| SUBSEQ |
---------- |
Yes |
Yes |
| Commonly-used-setters |
| BIT |
---------- |
Yes |
Yes |
| SBIT |
---------- |
Yes |
Yes |
| CHAR |
CodyNelson |
Yes |
No (needs to be fixed to ignore fill-pointers) |
| SCHAR |
---------- |
Yes |
Yes |
| SVREF |
CodyNelson |
Yes |
Yes |
| AREF |
CodyNelson |
Yes |
No (needs to be tested for multi-dimensional arrays) |
| Other-setters |
| CLASS-NAME |
|
No |
No |
| COMPILER-MACRO-FUNCTION |
|
No |
No |
| DEPOSIT-FIELD |
|
No |
No |
| DOCUMENTATION |
|
No |
No |
| DPB |
|
No |
No |
| FDEFINITION |
|
No |
No |
| FILL-POINTER |
---------- |
Yes |
Yes |
| FIND-CLASS |
|
No |
No |
| GET |
|
No |
No |
| GETHASH |
---------- |
Yes |
Yes |
| LBD |
---------- |
Yes |
Yes |
| LOGICAL-PATHNAME-TRANSLATIONS |
|
No |
No |
| MACRO-FUNCTION |
|
No |
No |
| MASK-FIELD |
---------- |
Yes |
Yes |
| READTABLE-CASE |
CodyNelson |
Yes |
Yes |
| ROW-MAJOR-AREF |
|
No |
No |
| SLOT-VALUE |
|
No |
No |
| SYMBOL-FUNCTION |
|
No |
No |
| SYMBOL-PLIST |
|
No |
No |
| SYMBOL-VALUE |
|
No |
No |
| Main Setf Functions |
Author |
Coded |
Completed |
| ASSERT |
|
No |
No |
| CCASE |
|
No |
No |
| CTYPECASE |
|
No |
No |
| DECF |
|
No |
No |
| DEFINE-MODIFY-MACRO |
|
No |
No |
| DEFINE-SETF-EXPANDER |
|
No |
No |
| DEFSETF |
---------- |
Yes |
Yes |
| GET-SETF-EXPANSION |
---------- |
Yes |
Yes |
| GETF |
---------- |
Yes |
Yes |
| INCF |
|
No |
No |
| POP |
---------- |
Yes |
Yes |
| PSETF |
|
No |
No |
| PUSH |
---------- |
Yes |
Yes |
| PUSHNEW |
---------- |
Yes |
Yes |
| REMF |
|
No |
No |
| ROTATEF |
|
No |
No |
| SETF |
---------- |
Yes |
Yes |
| SHIFTF |
|
No |
No |