# Is defining a function inside a loop without time penalty?

**URL:** <https://racket.discourse.group/t/is-defining-a-function-inside-a-loop-without-time-penalty/3392>\
**Category:** Questions & Answers\
**Created:** [December 4, 2024, 10:41am UTC](https://racket.discourse.group/t/is-defining-a-function-inside-a-loop-without-time-penalty/3392 "2024-12-04T10:41:43Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![damien\_mattei](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/damien_mattei/32/2706_2.png) [@damien\_mattei](https://racket.discourse.group/u/damien_mattei)\
**Post date:** [December 4, 2024, 11:51am UTC](https://racket.discourse.group/t/is-defining-a-function-inside-a-loop-without-time-penalty/3392/3 "2024-12-04T11:51:46Z")

</div>

thank you @soegaard , i had a little doubt, now it is clear:

> [@soegaard](#):
>
> Racket compiles the files ahead of time.

> [@soegaard](#):
>
> i suppose scheme/racket is not only interpreted ,  
> Can you rephrase?

i wanted to say interpreted , like the BASIC on an old computer (Apple 2 for example) ,interpreted for me is really at runtime only.

> [@soegaard](#):
>
> Give a complete example.

it was the `cal` procedure from this generated code:

```scheme
($nfx$
   data-xml
   <-
   (for/list
    ((one-data-row data-interpol) (one-trajectory-row data-trajectory))
    ($nfx$
     (index X_MSO Y_MSO Z_MSO VALx VALy VALz)
     <-
     (apply values (string-split one-data-row)))
    ($nfx$
     (time-stamp x_traj_mso y_traj_mso z_traj_mso)
     <-
     (apply values (string-split one-trajectory-row)))
    (define (cal val) ($nfx$ val * Bsw / B0))
    `(TR
      (TD ,time-stamp)
      (TD ,X_MSO)
      (TD ,Y_MSO)
      (TD ,Z_MSO)
      (TD ,(cal (string->number VALx)))
      (TD ,(cal (string->number VALy)))
      (TD ,(cal (string->number VALz))))))

```

generated from this scheme+ source code:

```scheme
{data-xml <- (for/list ([one-data-row data-interpol]
				[one-trajectory-row data-trajectory])

			       ;; take in SimulationData.txt Bo or Vo x,y,z, compute norm
			       ;; compute B or V in output file like this:
			       ;; B_x|y|z_XML=Bintermediate_unit_code_x|y|z * Bsw / |Bo input| with Bsw=10nT
			       
			       {(index X_MSO Y_MSO Z_MSO VALx VALy VALz) <- (apply values
										   (string-split one-data-row))}
			       {(time-stamp x_traj_mso y_traj_mso z_traj_mso) <- (apply values
											(string-split one-trajectory-row))}

			       (define (cal val) {val * Bsw / B0})
			    
			       `(TR (TD ,time-stamp)
				    (TD ,X_MSO)
				    (TD ,Y_MSO)
				    (TD ,Z_MSO)
				    (TD ,(cal (string->number VALx)))
				    (TD ,(cal (string->number VALy)))
				    (TD ,(cal (string->number VALz)))))}

```

just for info it is related from the other post, i'm debugging:

[https://racket.discourse.group/t/valid-numeric-entity-refused-by-xexpr-xml/3393](https://racket.discourse.group/t/valid-numeric-entity-refused-by-xexpr-xml/3393)

---

_[View the full topic](https://racket.discourse.group/t/is-defining-a-function-inside-a-loop-without-time-penalty/3392)._
