Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
12
Task/Generic-swap/Aime/generic-swap.aime
Normal file
12
Task/Generic-swap/Aime/generic-swap.aime
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
void
|
||||
__swap(&, &,,)
|
||||
{
|
||||
set(0, $3);
|
||||
set(1, $2);
|
||||
}
|
||||
|
||||
void
|
||||
swap(&, &)
|
||||
{
|
||||
xcall(xcall, __swap);
|
||||
}
|
||||
6
Task/Generic-swap/Emacs-Lisp/generic-swap-1.l
Normal file
6
Task/Generic-swap/Emacs-Lisp/generic-swap-1.l
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
(defun swap (a-sym b-sym)
|
||||
"Swap values of the variables given by A-SYM and B-SYM."
|
||||
(let ((a-val (symbol-value a-sym)))
|
||||
(set a-sym (symbol-value b-sym))
|
||||
(set b-sym a-val)))
|
||||
(swap 'a 'b)
|
||||
2
Task/Generic-swap/Emacs-Lisp/generic-swap-2.l
Normal file
2
Task/Generic-swap/Emacs-Lisp/generic-swap-2.l
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
(defmacro swap (a b)
|
||||
`(setq ,b (prog1 ,a (setq ,a ,b))))
|
||||
8
Task/Generic-swap/Emacs-Lisp/generic-swap-3.l
Normal file
8
Task/Generic-swap/Emacs-Lisp/generic-swap-3.l
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
(require 'cl)
|
||||
(defmacro swap (a b)
|
||||
`(psetf ,a ,b
|
||||
,b ,a))
|
||||
|
||||
(setq lst (list 123 456))
|
||||
(swap (car lst) (cadr lst))
|
||||
;; now lst is '(456 123)
|
||||
1
Task/Generic-swap/NewLISP/generic-swap.newlisp
Normal file
1
Task/Generic-swap/NewLISP/generic-swap.newlisp
Normal file
|
|
@ -0,0 +1 @@
|
|||
(swap a b)
|
||||
10
Task/Generic-swap/UNIX-Shell/generic-swap-1.sh
Normal file
10
Task/Generic-swap/UNIX-Shell/generic-swap-1.sh
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
$ swap() { typeset -n var1=$1 var2=$2; set -- "$var1" "$var2"; var1=$2; var2=$1; }
|
||||
$ a=1 b=2
|
||||
$ echo $a $b
|
||||
1 2
|
||||
$ swap a b
|
||||
$ echo $a $b
|
||||
2 1
|
||||
$ swap a b
|
||||
$ echo $a $b
|
||||
1 2
|
||||
10
Task/Generic-swap/UNIX-Shell/generic-swap-2.sh
Normal file
10
Task/Generic-swap/UNIX-Shell/generic-swap-2.sh
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
$ swap() { local var1=$1 var2=$2; set -- "${!var1}" "${!var2}"; declare -g "$var1"="$2" "$var2"="$1"; }
|
||||
$ a=1 b=2
|
||||
$ echo $a $b
|
||||
1 2
|
||||
$ swap a b
|
||||
$ echo $a $b
|
||||
2 1
|
||||
$ swap a b
|
||||
$ echo $a $b
|
||||
1 2
|
||||
Loading…
Add table
Add a link
Reference in a new issue