@@ -102,8 +102,7 @@ The foundation of ScaFi is the **field calculus**, which provides three core pri
102102``` scala
103103import it .unibo .scafi .language .xc .ExchangeLanguage
104104import it .unibo .scafi .language .xc .calculus .ExchangeCalculus
105- import it .unibo .scafi .libraries .FieldCalculusLibrary .*
106- import it .unibo .scafi .libraries .CommonLibrary .localId
105+ import it .unibo .scafi .libraries .All .*
107106
108107// Define your aggregate program using context functions
109108def myProgram (using context : ExchangeCalculus & ExchangeLanguage ): Int =
@@ -126,13 +125,11 @@ def myProgram(using context: ExchangeCalculus & ExchangeLanguage): Int =
126125A classic aggregate programming example—computing distance from a source:
127126
128127``` scala
129- import it .unibo .scafi .libraries .GradientLibrary .*
130- import it .unibo .scafi .libraries .CommonLibrary .*
131- import it .unibo .scafi .message .Codables .given
128+ import it .unibo .scafi .libraries .All .*
132129
133- def gradient (using context : ExchangeCalculus & ExchangeLanguage ): Double =
130+ def gradient (using context : ExchangeCalculus & ExchangeLanguage { type DeviceId = Int } ): Double =
134131 // Compute distance from source using neighbor distance + edge cost
135- distanceTo[Array [ Byte ] , Double ](
132+ distanceTo[Double , Double ](
136133 source = localId == 0 , // Device 0 is the source
137134 distances = neighborValues(1.0 ) // Each hop costs 1.0
138135 )
@@ -143,9 +140,9 @@ def gradient(using context: ExchangeCalculus & ExchangeLanguage): Double =
143140Control information flow with domain branching:
144141
145142``` scala
146- import it .unibo .scafi .libraries .BranchingLibrary .*
143+ import it .unibo .scafi .libraries .All .*
147144
148- def conditionalBehavior (using context : ExchangeCalculus & ExchangeLanguage ): String =
145+ def conditionalBehavior (using context : ExchangeCalculus & ExchangeLanguage { type DeviceId = Int } ): String =
149146 val distanceFromSource = gradient
150147
151148 // Split the network into two independent computational domains
@@ -161,18 +158,17 @@ def conditionalBehavior(using context: ExchangeCalculus & ExchangeLanguage): Str
161158Under the hood, ScaFi implements the ** Exchange Calculus** , a more expressive variant of field calculus:
162159
163160``` scala
164- import it .unibo .scafi .libraries .ExchangeCalculusLibrary .*
165- import it .unibo .scafi .language .xc .syntax .ReturnSending .returning
161+ import it .unibo .scafi .libraries .All .*
166162
167163def exchangeExample (using context : ExchangeCalculus & ExchangeLanguage ): Int =
168164 // exchange: send and receive different values
169165 exchange(0 ) { receivedValues =>
170166 val maxFromNeighbors = receivedValues.withoutSelf.max
171- val myValue = localId + maxFromNeighbors
167+ val myValue = 1 + maxFromNeighbors
172168
173169 // Return one value but send another to neighbors
174170 returning(myValue) send (myValue + 1 )
175- }
171+ }(localId)
176172```
177173
178174### Complete Example: Self-Healing Gradient
@@ -181,9 +177,7 @@ Here's a complete example showing ScaFi's resilience:
181177
182178``` scala
183179import it .unibo .scafi .language .xc .{ExchangeLanguage , ExchangeCalculus }
184- import it .unibo .scafi .libraries .GradientLibrary .*
185- import it .unibo .scafi .libraries .CommonLibrary .*
186- import it .unibo .scafi .message .Codables .given
180+ import it .unibo .scafi .libraries .All .*
187181
188182// Define an aggregate program that computes a self-healing gradient
189183def selfHealingGradient (
@@ -193,7 +187,7 @@ def selfHealingGradient(
193187
194188 // Automatically computes and maintains shortest distance from source
195189 // Adapts to topology changes and device failures
196- distanceTo[Array [ Byte ] , Double ](isSource, neighborValues(hopDistance))
190+ distanceTo[Double , Double ](isSource, neighborValues(hopDistance))
197191
198192// In practice, this would be executed by the ScaFi engine across devices
199193// Each device runs the same program but operates on its local context
0 commit comments