comparison src/eval.c @ 4642:48b45a606961

Support #'function-arglist with built-in special forms. Also fix a couple of bugs in lisp/help.el. lisp/ChangeLog addition: 2009-06-14 Aidan Kehoe <kehoea@parhasard.net> * help.el (describe-function-1): Check macro-p, not macrop, when describing whether a symbol has an associated macro or an associated function. Relevant with autoloaded macros. (function-arglist): Accept multi-line arglists in built-in functions, as found in #'write-region-internal. #'dontusethis-set-symbol-value-handler is still broken for other reasons. src/ChangeLog addition: 2009-06-14 Aidan Kehoe <kehoea@parhasard.net> * eval.c (For): * eval.c (Fand): * eval.c (Fif): * eval.c (Fwhen): * eval.c (Fcond): * eval.c (Fprogn): * eval.c (Fprog1): * eval.c (Fprog2): * eval.c (FletX): * eval.c (Flet): * eval.c (Fwhile): * eval.c (Fdefvar): * eval.c (Fdefconst): * eval.c (Frun_hooks): * eval.c (Frun_hooks_with_args): * eval.c (Frun_hooks_with_args_until_success): * eval.c (Frun_hooks_with_args_until_failure): Add arguments information, understood by #'function-arglist, to all these special forms, functions and macros. Remove the argument information that was already there that was not understood by #'function-arglist.
author Aidan Kehoe <kehoea@parhasard.net>
date Sun, 14 Jun 2009 15:07:13 +0100
parents 9dd42cb187ed
children f8d7d8202635
comparison
equal deleted inserted replaced
4641:a90b63846dc4 4642:48b45a606961
814 814
815 /* Except for Fprogn(), the basic special forms below are only called 815 /* Except for Fprogn(), the basic special forms below are only called
816 from interpreted code. The byte compiler turns them into bytecodes. */ 816 from interpreted code. The byte compiler turns them into bytecodes. */
817 817
818 DEFUN ("or", For, 0, UNEVALLED, 0, /* 818 DEFUN ("or", For, 0, UNEVALLED, 0, /*
819 Eval args until one of them yields non-nil, then return that value. 819 Eval ARGS until one of them yields non-nil, then return that value.
820 The remaining args are not evalled at all. 820 The remaining ARGS are not evalled at all.
821 If all args return nil, return nil. 821 If all args return nil, return nil.
822
823 arguments: (&rest ARGS)
822 */ 824 */
823 (args)) 825 (args))
824 { 826 {
825 /* This function can GC */ 827 /* This function can GC */
826 REGISTER Lisp_Object val; 828 REGISTER Lisp_Object val;
833 835
834 return Qnil; 836 return Qnil;
835 } 837 }
836 838
837 DEFUN ("and", Fand, 0, UNEVALLED, 0, /* 839 DEFUN ("and", Fand, 0, UNEVALLED, 0, /*
838 Eval args until one of them yields nil, then return nil. 840 Eval ARGS until one of them yields nil, then return nil.
839 The remaining args are not evalled at all. 841 The remaining ARGS are not evalled at all.
840 If no arg yields nil, return the last arg's value. 842 If no arg yields nil, return the last arg's value.
843
844 arguments: (&rest ARGS)
841 */ 845 */
842 (args)) 846 (args))
843 { 847 {
844 /* This function can GC */ 848 /* This function can GC */
845 REGISTER Lisp_Object val = Qt; 849 REGISTER Lisp_Object val = Qt;
852 856
853 return val; 857 return val;
854 } 858 }
855 859
856 DEFUN ("if", Fif, 2, UNEVALLED, 0, /* 860 DEFUN ("if", Fif, 2, UNEVALLED, 0, /*
857 \(if COND THEN ELSE...): if COND yields non-nil, do THEN, else do ELSE... 861 If COND yields non-nil, do THEN, else do ELSE.
858 Returns the value of THEN or the value of the last of the ELSE's. 862 Returns the value of THEN or the value of the last of the ELSE's.
859 THEN must be one expression, but ELSE... can be zero or more expressions. 863 THEN must be one expression, but ELSE... can be zero or more expressions.
860 If COND yields nil, and there are no ELSE's, the value is nil. 864 If COND yields nil, and there are no ELSE's, the value is nil.
865
866 arguments: (COND THEN &rest ELSE)
861 */ 867 */
862 (args)) 868 (args))
863 { 869 {
864 /* This function can GC */ 870 /* This function can GC */
865 Lisp_Object condition = XCAR (args); 871 Lisp_Object condition = XCAR (args);
874 880
875 /* Macros `when' and `unless' are trivially defined in Lisp, 881 /* Macros `when' and `unless' are trivially defined in Lisp,
876 but it helps for bootstrapping to have them ALWAYS defined. */ 882 but it helps for bootstrapping to have them ALWAYS defined. */
877 883
878 DEFUN ("when", Fwhen, 1, MANY, 0, /* 884 DEFUN ("when", Fwhen, 1, MANY, 0, /*
879 \(when COND BODY...): if COND yields non-nil, do BODY, else return nil. 885 If COND yields non-nil, do BODY, else return nil.
880 BODY can be zero or more expressions. If BODY is nil, return nil. 886 BODY can be zero or more expressions. If BODY is nil, return nil.
887
888 arguments: (COND &rest BODY)
881 */ 889 */
882 (int nargs, Lisp_Object *args)) 890 (int nargs, Lisp_Object *args))
883 { 891 {
884 Lisp_Object cond = args[0]; 892 Lisp_Object cond = args[0];
885 Lisp_Object body; 893 Lisp_Object body;
893 901
894 return list3 (Qif, cond, body); 902 return list3 (Qif, cond, body);
895 } 903 }
896 904
897 DEFUN ("unless", Funless, 1, MANY, 0, /* 905 DEFUN ("unless", Funless, 1, MANY, 0, /*
898 \(unless COND BODY...): if COND yields nil, do BODY, else return nil. 906 If COND yields nil, do BODY, else return nil.
899 BODY can be zero or more expressions. If BODY is nil, return nil. 907 BODY can be zero or more expressions. If BODY is nil, return nil.
908
909 arguments: (COND &rest BODY)
900 */ 910 */
901 (int nargs, Lisp_Object *args)) 911 (int nargs, Lisp_Object *args))
902 { 912 {
903 Lisp_Object cond = args[0]; 913 Lisp_Object cond = args[0];
904 Lisp_Object body = Flist (nargs-1, args+1); 914 Lisp_Object body = Flist (nargs-1, args+1);
905 return Fcons (Qif, Fcons (cond, Fcons (Qnil, body))); 915 return Fcons (Qif, Fcons (cond, Fcons (Qnil, body)));
906 } 916 }
907 917
908 DEFUN ("cond", Fcond, 0, UNEVALLED, 0, /* 918 DEFUN ("cond", Fcond, 0, UNEVALLED, 0, /*
909 \(cond CLAUSES...): try each clause until one succeeds. 919 Try each clause until one succeeds.
910 Each clause looks like (CONDITION BODY...). CONDITION is evaluated 920 Each clause looks like (CONDITION BODY...). CONDITION is evaluated
911 and, if the value is non-nil, this clause succeeds: 921 and, if the value is non-nil, this clause succeeds:
912 then the expressions in BODY are evaluated and the last one's 922 then the expressions in BODY are evaluated and the last one's
913 value is the value of the cond-form. 923 value is the value of the cond-form.
914 If no clause succeeds, cond returns nil. 924 If no clause succeeds, cond returns nil.
915 If a clause has one element, as in (CONDITION), 925 If a clause has one element, as in (CONDITION),
916 CONDITION's value if non-nil is returned from the cond-form. 926 CONDITION's value if non-nil is returned from the cond-form.
927
928 arguments: (&rest CLAUSES)
917 */ 929 */
918 (args)) 930 (args))
919 { 931 {
920 /* This function can GC */ 932 /* This function can GC */
921 REGISTER Lisp_Object val; 933 REGISTER Lisp_Object val;
936 948
937 return Qnil; 949 return Qnil;
938 } 950 }
939 951
940 DEFUN ("progn", Fprogn, 0, UNEVALLED, 0, /* 952 DEFUN ("progn", Fprogn, 0, UNEVALLED, 0, /*
941 \(progn BODY...): eval BODY forms sequentially and return value of last one. 953 Eval BODY forms sequentially and return value of last one.
954
955 arguments: (&rest BODY)
942 */ 956 */
943 (args)) 957 (args))
944 { 958 {
945 /* This function can GC */ 959 /* This function can GC */
946 /* Caller must provide a true list in ARGS */ 960 /* Caller must provide a true list in ARGS */
961 /* Fprog1() is the canonical example of a function that must GCPRO a 975 /* Fprog1() is the canonical example of a function that must GCPRO a
962 Lisp_Object across calls to Feval(). */ 976 Lisp_Object across calls to Feval(). */
963 977
964 DEFUN ("prog1", Fprog1, 1, UNEVALLED, 0, /* 978 DEFUN ("prog1", Fprog1, 1, UNEVALLED, 0, /*
965 Similar to `progn', but the value of the first form is returned. 979 Similar to `progn', but the value of the first form is returned.
966 \(prog1 FIRST BODY...): All the arguments are evaluated sequentially. 980
967 The value of FIRST is saved during evaluation of the remaining args, 981 All the arguments are evaluated sequentially. The value of FIRST is saved
968 whose values are discarded. 982 during evaluation of the remaining args, whose values are discarded.
983
984 arguments: (FIRST &rest BODY)
969 */ 985 */
970 (args)) 986 (args))
971 { 987 {
972 /* This function can GC */
973 Lisp_Object val; 988 Lisp_Object val;
974 struct gcpro gcpro1; 989 struct gcpro gcpro1;
975 990
976 val = Feval (XCAR (args)); 991 val = Feval (XCAR (args));
977 992
986 return val; 1001 return val;
987 } 1002 }
988 1003
989 DEFUN ("prog2", Fprog2, 2, UNEVALLED, 0, /* 1004 DEFUN ("prog2", Fprog2, 2, UNEVALLED, 0, /*
990 Similar to `progn', but the value of the second form is returned. 1005 Similar to `progn', but the value of the second form is returned.
991 \(prog2 FIRST SECOND BODY...): All the arguments are evaluated sequentially. 1006
992 The value of SECOND is saved during evaluation of the remaining args, 1007 All the arguments are evaluated sequentially. The value of SECOND is saved
993 whose values are discarded. 1008 during evaluation of the remaining args, whose values are discarded.
1009
1010 arguments: (FIRST SECOND &rest BODY)
994 */ 1011 */
995 (args)) 1012 (args))
996 { 1013 {
997 /* This function can GC */ 1014 /* This function can GC */
998 Lisp_Object val; 1015 Lisp_Object val;
1013 UNGCPRO; 1030 UNGCPRO;
1014 return val; 1031 return val;
1015 } 1032 }
1016 1033
1017 DEFUN ("let*", FletX, 1, UNEVALLED, 0, /* 1034 DEFUN ("let*", FletX, 1, UNEVALLED, 0, /*
1018 \(let* VARLIST BODY...): bind variables according to VARLIST then eval BODY. 1035 Bind variables according to VARLIST then eval BODY.
1019 The value of the last form in BODY is returned. 1036 The value of the last form in BODY is returned.
1020 Each element of VARLIST is a symbol (which is bound to nil) 1037 Each element of VARLIST is a symbol (which is bound to nil)
1021 or a list (SYMBOL VALUEFORM) (which binds SYMBOL to the value of VALUEFORM). 1038 or a list (SYMBOL VALUEFORM) (which binds SYMBOL to the value of VALUEFORM).
1022 Each VALUEFORM can refer to the symbols already bound by this VARLIST. 1039 Each VALUEFORM can refer to the symbols already bound by this VARLIST.
1040
1041 arguments: (VARLIST &rest BODY)
1023 */ 1042 */
1024 (args)) 1043 (args))
1025 { 1044 {
1026 /* This function can GC */ 1045 /* This function can GC */
1027 Lisp_Object varlist = XCAR (args); 1046 Lisp_Object varlist = XCAR (args);
1053 } 1072 }
1054 return unbind_to_1 (speccount, Fprogn (body)); 1073 return unbind_to_1 (speccount, Fprogn (body));
1055 } 1074 }
1056 1075
1057 DEFUN ("let", Flet, 1, UNEVALLED, 0, /* 1076 DEFUN ("let", Flet, 1, UNEVALLED, 0, /*
1058 \(let VARLIST BODY...): bind variables according to VARLIST then eval BODY. 1077 Bind variables according to VARLIST then eval BODY.
1059 The value of the last form in BODY is returned. 1078 The value of the last form in BODY is returned.
1060 Each element of VARLIST is a symbol (which is bound to nil) 1079 Each element of VARLIST is a symbol (which is bound to nil)
1061 or a list (SYMBOL VALUEFORM) (which binds SYMBOL to the value of VALUEFORM). 1080 or a list (SYMBOL VALUEFORM) (which binds SYMBOL to the value of VALUEFORM).
1062 All the VALUEFORMs are evalled before any symbols are bound. 1081 All the VALUEFORMs are evalled before any symbols are bound.
1082
1083 arguments: (VARLIST &rest BODY)
1063 */ 1084 */
1064 (args)) 1085 (args))
1065 { 1086 {
1066 /* This function can GC */ 1087 /* This function can GC */
1067 Lisp_Object varlist = XCAR (args); 1088 Lisp_Object varlist = XCAR (args);
1122 1143
1123 return unbind_to_1 (speccount, Fprogn (body)); 1144 return unbind_to_1 (speccount, Fprogn (body));
1124 } 1145 }
1125 1146
1126 DEFUN ("while", Fwhile, 1, UNEVALLED, 0, /* 1147 DEFUN ("while", Fwhile, 1, UNEVALLED, 0, /*
1127 \(while TEST BODY...): if TEST yields non-nil, eval BODY... and repeat. 1148 If TEST yields non-nil, eval BODY... and repeat.
1128 The order of execution is thus TEST, BODY, TEST, BODY and so on 1149 The order of execution is thus TEST, BODY, TEST, BODY and so on
1129 until TEST returns nil. 1150 until TEST returns nil.
1151
1152 arguments: (TEST &rest BODY)
1130 */ 1153 */
1131 (args)) 1154 (args))
1132 { 1155 {
1133 /* This function can GC */ 1156 /* This function can GC */
1134 Lisp_Object test = XCAR (args); 1157 Lisp_Object test = XCAR (args);
1253 return define_function (XCAR (args), 1276 return define_function (XCAR (args),
1254 Fcons (Qmacro, Fcons (Qlambda, XCDR (args)))); 1277 Fcons (Qmacro, Fcons (Qlambda, XCDR (args))));
1255 } 1278 }
1256 1279
1257 DEFUN ("defvar", Fdefvar, 1, UNEVALLED, 0, /* 1280 DEFUN ("defvar", Fdefvar, 1, UNEVALLED, 0, /*
1258 \(defvar SYMBOL INITVALUE DOCSTRING): define SYMBOL as a variable. 1281 Define SYMBOL as a variable.
1259 You are not required to define a variable in order to use it, 1282 You are not required to define a variable in order to use it,
1260 but the definition can supply documentation and an initial value 1283 but the definition can supply documentation and an initial value
1261 in a way that tags can recognize. 1284 in a way that tags can recognize.
1262 1285
1263 INITVALUE is evaluated, and used to set SYMBOL, only if SYMBOL's value is 1286 INITVALUE is evaluated, and used to set SYMBOL, only if SYMBOL's value is
1270 If DOCSTRING starts with *, this variable is identified as a user option. 1293 If DOCSTRING starts with *, this variable is identified as a user option.
1271 This means that M-x set-variable recognizes it. 1294 This means that M-x set-variable recognizes it.
1272 If INITVALUE is missing, SYMBOL's value is not set. 1295 If INITVALUE is missing, SYMBOL's value is not set.
1273 1296
1274 In lisp-interaction-mode defvar is treated as defconst. 1297 In lisp-interaction-mode defvar is treated as defconst.
1298
1299 arguments: (SYMBOL &optional INITVALUE DOCSTRING)
1275 */ 1300 */
1276 (args)) 1301 (args))
1277 { 1302 {
1278 /* This function can GC */ 1303 /* This function can GC */
1279 Lisp_Object sym = XCAR (args); 1304 Lisp_Object sym = XCAR (args);
1308 LOADHIST_ATTACH (sym); 1333 LOADHIST_ATTACH (sym);
1309 return sym; 1334 return sym;
1310 } 1335 }
1311 1336
1312 DEFUN ("defconst", Fdefconst, 2, UNEVALLED, 0, /* 1337 DEFUN ("defconst", Fdefconst, 2, UNEVALLED, 0, /*
1313 \(defconst SYMBOL INITVALUE DOCSTRING): define SYMBOL as a constant 1338 Define SYMBOL as a constant variable.
1314 variable.
1315 The intent is that programs do not change this value, but users may. 1339 The intent is that programs do not change this value, but users may.
1316 Always sets the value of SYMBOL to the result of evalling INITVALUE. 1340 Always sets the value of SYMBOL to the result of evalling INITVALUE.
1317 If SYMBOL is buffer-local, its default value is what is set; 1341 If SYMBOL is buffer-local, its default value is what is set;
1318 buffer-local values are not affected. 1342 buffer-local values are not affected.
1319 DOCSTRING is optional. 1343 DOCSTRING is optional.
1323 Note: do not use `defconst' for user options in libraries that are not 1347 Note: do not use `defconst' for user options in libraries that are not
1324 normally loaded, since it is useful for users to be able to specify 1348 normally loaded, since it is useful for users to be able to specify
1325 their own values for such variables before loading the library. 1349 their own values for such variables before loading the library.
1326 Since `defconst' unconditionally assigns the variable, 1350 Since `defconst' unconditionally assigns the variable,
1327 it would override the user's choice. 1351 it would override the user's choice.
1352
1353 arguments: (SYMBOL &optional INITVALUE DOCSTRING)
1328 */ 1354 */
1329 (args)) 1355 (args))
1330 { 1356 {
1331 /* This function can GC */ 1357 /* This function can GC */
1332 Lisp_Object sym = XCAR (args); 1358 Lisp_Object sym = XCAR (args);
4283 If the value is a function, it is called with no arguments. 4309 If the value is a function, it is called with no arguments.
4284 If it is a list, the elements are called, in order, with no arguments. 4310 If it is a list, the elements are called, in order, with no arguments.
4285 4311
4286 To make a hook variable buffer-local, use `make-local-hook', 4312 To make a hook variable buffer-local, use `make-local-hook',
4287 not `make-local-variable'. 4313 not `make-local-variable'.
4314
4315 arguments: (&rest HOOKS)
4288 */ 4316 */
4289 (int nargs, Lisp_Object *args)) 4317 (int nargs, Lisp_Object *args))
4290 { 4318 {
4291 REGISTER int i; 4319 REGISTER int i;
4292 4320
4307 It is best not to depend on the value returned by `run-hook-with-args', 4335 It is best not to depend on the value returned by `run-hook-with-args',
4308 as that may change. 4336 as that may change.
4309 4337
4310 To make a hook variable buffer-local, use `make-local-hook', 4338 To make a hook variable buffer-local, use `make-local-hook',
4311 not `make-local-variable'. 4339 not `make-local-variable'.
4340
4341 arguments: (HOOK &rest ARGS)
4312 */ 4342 */
4313 (int nargs, Lisp_Object *args)) 4343 (int nargs, Lisp_Object *args))
4314 { 4344 {
4315 return run_hook_with_args (nargs, args, RUN_HOOKS_TO_COMPLETION); 4345 return run_hook_with_args (nargs, args, RUN_HOOKS_TO_COMPLETION);
4316 } 4346 }
4323 returns a non-nil value. Then we return that value. 4353 returns a non-nil value. Then we return that value.
4324 If all the functions return nil, we return nil. 4354 If all the functions return nil, we return nil.
4325 4355
4326 To make a hook variable buffer-local, use `make-local-hook', 4356 To make a hook variable buffer-local, use `make-local-hook',
4327 not `make-local-variable'. 4357 not `make-local-variable'.
4358
4359 arguments: (HOOK &rest ARGS)
4328 */ 4360 */
4329 (int nargs, Lisp_Object *args)) 4361 (int nargs, Lisp_Object *args))
4330 { 4362 {
4331 return run_hook_with_args (nargs, args, RUN_HOOKS_UNTIL_SUCCESS); 4363 return run_hook_with_args (nargs, args, RUN_HOOKS_UNTIL_SUCCESS);
4332 } 4364 }
4339 returns nil. Then we return nil. 4371 returns nil. Then we return nil.
4340 If all the functions return non-nil, we return non-nil. 4372 If all the functions return non-nil, we return non-nil.
4341 4373
4342 To make a hook variable buffer-local, use `make-local-hook', 4374 To make a hook variable buffer-local, use `make-local-hook',
4343 not `make-local-variable'. 4375 not `make-local-variable'.
4376
4377 arguments: (HOOK &rest ARGS)
4344 */ 4378 */
4345 (int nargs, Lisp_Object *args)) 4379 (int nargs, Lisp_Object *args))
4346 { 4380 {
4347 return run_hook_with_args (nargs, args, RUN_HOOKS_UNTIL_FAILURE); 4381 return run_hook_with_args (nargs, args, RUN_HOOKS_UNTIL_FAILURE);
4348 } 4382 }