( defun make-dvec ( input-dimension initial-element ) ( make-array input-dimension :element-type 'double-float :initial-element initial-element )) ( defmacro dovec ( vec var &body body ) ` ( loop for , var fixnum from 0 to ( 1- ( length , vec )) do ,@ body )) ;; 通常の書き方 ( declaim ( ftype ( function (( simple-array double-float ) ( simple-array double-float )) double-float ) dot )) ( defun dot ( x y ) ( declare ( type ( simple-array double-float ) x y ) ( optimize ( speed 3 ) ( safety 0 ) ( debug 0 ))) ( let (( result 0.0d0 )) ( declare ( type double-float result )) ( dovec x i ( incf result ( * ( aref x i ) ( aref y i )))) result )) ;; defntとtletを使ったバージョン ( defnt ( dot double-float ) (( x ( simple-array double-float )) ( y ( simple-array double-float ))) ( tlet (( result 0d0 double-float )) ( dovec x i ( incf result ( * ( aref x i ) ( aref y i )))) result ))