1(in-package #:tutorial-implementation)
2
3;;;; Licensed under the Apache License, Version 2.0 (the "License");
4;;;; you may not use this file except in compliance with the License.
5;;;; You may obtain a copy of the License at
6;;;;
7;;;;     http://www.apache.org/licenses/LICENSE-2.0
8;;;;
9;;;; Unless required by applicable law or agreed to in writing, software
10;;;; distributed under the License is distributed on an "AS IS" BASIS,
11;;;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12;;;; See the License for the specific language governing permissions and
13;;;; limitations under the License.
14
15(defun tutorial.calculator-implementation:ping ()
16  (format t "ping()~%"))
17
18(defun tutorial.calculator-implementation:add (num1 num2)
19  (format t "add(~a, ~a)~%" num1 num2)
20  (+ num1 num2))
21
22(defun tutorial.calculator-implementation:calculate (logid work)
23  (format t "calculate(~a, ~a)~%" logid work)
24  (handler-case
25      (let* ((num1 (tutorial:work-num1 work))
26             (num2 (tutorial:work-num2 work))
27             (op (tutorial:work-op work))
28             (result
29              (cond
30                ((= op tutorial:operation.add) (+ num1 num2))
31                ((= op tutorial:operation.subtract) (- num1 num2))
32                ((= op tutorial:operation.multiply) (* num1 num2))
33                ((= op tutorial:operation.divide) (/ num1 num2)))))
34        (shared-implementation::add-log logid result)
35        result)
36    (division-by-zero () (error 'tutorial:invalidoperation
37                                :why "Division by zero."
38                                :what-op (tutorial:work-op work)))))
39
40(defun tutorial.calculator-implementation:zip ()
41  (format t "zip()~%"))
42