LINUX.ORG.RU

Разбор кода на McCLIM

 


0

3

Там где не получается сообразить поставил много вопросительных знаков. Надеюсь получить ответы от профессионалов.

Распространителям зарубежной литературы здесь нечего делать, идите лесом.

(in-package :common-lisp-user)
(defpackage :first-app
	    (:use :clim :clim-lisp)
	    (:export first-app))
(in-package :first-app)

(defun av-test-display-screen (frame pane)
  (declare (ignore frame)) 
  (with-text-size (pane :large)
    (fresh-line pane)
    (present '(com-reset-clock-1) 'command :stream pane)
    (fresh-line pane)))

(define-application-frame av-test ()
  ((own-window-p :initform nil)) ;;  These slots will typically hold
                                 ;;  any per-instance frame state.

  (:menu-bar t)
  (:panes
   (screen :application
           :display-time t
	   :display-function #'av-test-display-screen
           :text-style (make-text-style :sans-serif :roman :normal))
   (interactor :interactor :min-width 600)
   (doc :pointer-documentation))
  (:layouts
   (defaults
	 (vertically ()
	   screen
	   interactor
	   doc))))

;; default-frame-top-level will also establish a simple restart
;; for abort, and bind the standard stream variables. *query-io* will be bound
;; to the value returned by frame-query-io
(defun reset-clock-1 (&key (stream *query-io*) (ow t))
;;                            ^^^    ^^^        ^  ^
;;                     keyword-name   var     k-n  v
  (multiple-value-bind (second minute hour day month)
      (decode-universal-time (get-universal-time))
    (declare (ignore second)) ;; self explanatory, var second is not used
                              ;; anywhere
    (restart-case
	;; restartable-form
	(progn
	  ;; For instance, an accepting-values whose fields consist of
	  ;; gadgets may appear in an ordinary CLIM
          ;; stream pane.
	  ;; For example, accepting-values dialogs can be implemented by
          ;; using an encapsulating stream that tailors calls to accept and
	  ;; prompt-for-accept in such a way that the output is captured and
	  ;; formatted into a dialog that contains prompts and fields
          ;; that can be clicked on and modified by the user.

	  ;; (For example, the behavior of accepting-values can be implemented
	  ;; by creating a special class of stream that turns calls to
	  ;; accept into fields of a dialog.) ????????????? HOW TO???

	  ;; accepting-values (&optional stream &key own-window exit-boxes
	  ;; initially-select-query-identifier modify-initial-query
	  ;; resynchronize-every-pass resize-frame align-prompts label
	  ;; scroll-bars x-position y-position width height command-table
	  ;; frame-class) &body body   [Macro]

	  (clim:accepting-values (stream :own-window ow)
				 ;; (accepting-values (stream :own-window ow)
				 ;;            same as?????
				 ;; (accepting-values
				 ;; (&optional stream
				 ;; &key own-window
				 ;; what is ow)   ??????????
	    (format stream "Enter the time~%")
	    (setq month (clim:accept 'integer :stream stream
				      :default month :prompt "Month"))
	    (terpri stream)
	    (setq day (clim:accept 'integer :stream stream
				    :default day :prompt "Day"))
	    (terpri stream)
	    (setq hour (clim:accept 'integer :stream stream
				     :default hour :prompt "Hour"))
	    (terpri stream)
	    (setq minute (clim:accept 'integer :stream stream
				       :default minute :prompt "Minute")))
	  ;; This could be code to reset the time, but instead
	  ;; we’re just printing it out
	  (format nil "New values: Month: ~D, Day: ~D, Time: ~D:~2,'0D."
		  month day hour minute))
      ;; case-name is abort, it names this restart. 
      (abort () (format nil "Time not set")))))

(define-av-test-command (com-reset-clock-1 :name t :menu nil) ()
  (with-slots (own-window-p) clim:*application-frame*
    (format t "Result: ~S~%" (multiple-value-list
			      ;; (defun reset-clock-1
			      ;; (&key (stream *query-io*) (ow t)) ...)
			      (reset-clock-1 :ow own-window-p))))
  (finish-output *standard-output*)) ;;       ^         ^
;;                                            |      av-test slot
;;                                          no idea???
(defun first-app ()
(run-frame-top-level (make-application-frame 'av-test)))

Ответ на: комментарий от saufesma

Так у тебя выше же функция эта определена:

(defun reset-clock-1 (&key (stream *query-io*) (ow t))

Ну и там есть аргумент ow, который по умолчанию t, то есть когда значение не задано.

turtle_bazon ★★★★★
()
Ответ на: комментарий от turtle_bazon

аргумент ow, который по умолчанию t, то есть когда значение не задано.

здесь он вроде не аргумент, а параметр, ow is keyword name. Почему он здесь такой :ow

(reset-clock-1 :ow own-window-p)

вроде как не туда смотрим. Жду ответа от производителя.

saufesma
() автор топика
Ответ на: комментарий от turtle_bazon

И ещё, в CLOS есть понятие как precedence lists, найти нигде не могу, а как из спецификации это дело вытащить тоже не понятно. Всё тускло. Производитель молчит.

saufesma
() автор топика
Ответ на: комментарий от Nervous

это такой борщесинтаксис для деструктуризации аргументов.

Будь я программистом, я бы понял о чём речь.

saufesma
() автор топика
Ответ на: комментарий от saufesma

Деструктуризация

(destructuring assignment) – это особый синтаксис присваивания, при котором можно присвоить массив или объект сразу нескольким переменным, разбив его на части.

борщесинтаксис

ну, это местный мем про «мамкин борщ» и наколенные самоделки

aol ★★★★★
()
Ответ на: комментарий от saufesma

Он тут аргумент. Но да, кейвор бейзед. То есть без определённого порядка, просто по ключу :ow ты отдаёшь данные own-window-p

turtle_bazon ★★★★★
()
Ответ на: комментарий от turtle_bazon

ты сначала с базовыми вещами разберись

Sonya Keene Common Lisp Object-orienting programming page 31 3.5 Defining the implementation methods

Throughout this discussion, keep in mind the distinction between the terms argument and parameter. You provide arguments to a Lisp function when you call it, and you name the parameters of the function when you define it.

иногда сам почитывай.

Вот ещё попробовал методом тыка

(define-av-test-command (com-reset-clock-1 :name t :menu nil) ()
  (with-slots (own-window-p) clim:*application-frame*
    (format t "Result: ~S~%" (multiple-value-list
			      (reset-clock-1 ow own-window-p))))
  (finish-output *standard-output*))
; in: DEFINE-AV-TEST-COMMAND (COM-RESET-CLOCK-1 :NAME T :MENU NIL)
;     (FIRST-APP::RESET-CLOCK-1 FIRST-APP::OW FIRST-APP::OWN-WINDOW-P)
; 
; caught WARNING:
;   undefined variable: OW
; 
; compilation unit finished
;   Undefined variable:
;     OW
;   caught 1 WARNING condition
COM-RESET-CLOCK-1
saufesma
() автор топика
Ответ на: комментарий от turtle_bazon

Ответ от производителя

The application frame has a slot OWN-WINDOW-P . This should control whether the reset clock UI uses its own dialog window for resetting the clock values.

if one uses the command :RESET CLOCK 1, then the reset-clock-1 function gets called. It gets called with keyword arg :OW and its value is the value of the slot value of the application frame.

Inside the function RESET-CLOCK-1 there is use of the macro CLIM:ACCEPTING-VALUES. The value of the variable OW is used as a value for the keyword option :OWN-WINDOW. At runtime this macro then will either

:own-window nil -> create the UI for resetting the clock inline

or

:own-window t -> create a new window dialog for resetting the clock

saufesma
() автор топика
Ответ на: комментарий от turtle_bazon

Ну прям настоящий лоровец.

Иногда достаёт. А сейчас с производителем вошкаюсь, надеюсь разберусь. Ну и здесь потом отпишусь.

saufesma
() автор топика
Вы не можете добавлять комментарии в эту тему. Тема перемещена в архив.