@@ -31,7 +31,8 @@ impl Context {
31
31
let mut named = Self :: builtin_mono_trait ( NAMED , 2 ) ;
32
32
named. register_builtin_erg_decl ( FUNC_NAME , Str , Visibility :: BUILTIN_PUBLIC ) ;
33
33
let mut sized = Self :: builtin_mono_trait ( SIZED , 2 ) ;
34
- let t = fn0_met ( mono ( SIZED ) , Nat ) . quantify ( ) ;
34
+ let ret_t = if PYTHON_MODE { Int } else { Nat } ;
35
+ let t = fn0_met ( mono ( SIZED ) , ret_t) . quantify ( ) ;
35
36
sized. register_builtin_erg_decl ( FUNDAMENTAL_LEN , t, Visibility :: BUILTIN_PUBLIC ) ;
36
37
let mut copy = Self :: builtin_mono_trait ( COPY , 2 ) ;
37
38
let Slf = mono_q ( SELF , subtypeof ( mono ( COPY ) ) ) ;
@@ -227,15 +228,24 @@ impl Context {
227
228
/* Iterable */
228
229
let mut iterable = Self :: builtin_poly_trait ( ITERABLE , vec ! [ PS :: t_nd( TY_T ) ] , 2 ) ;
229
230
iterable. register_superclass ( poly ( OUTPUT , vec ! [ ty_tp( T . clone( ) ) ] ) , & output) ;
230
- let Slf = mono_q ( SELF , subtypeof ( poly ( ITERABLE , vec ! [ ty_tp( T . clone( ) ) ] ) ) ) ;
231
- let t = fn0_met ( Slf . clone ( ) , proj ( Slf , ITER ) ) . quantify ( ) ;
232
- iterable. register_builtin_decl (
233
- FUNC_ITER ,
234
- t,
235
- Visibility :: BUILTIN_PUBLIC ,
236
- Some ( FUNDAMENTAL_ITER ) ,
237
- ) ;
238
- iterable. register_builtin_erg_decl ( ITER , Type , Visibility :: BUILTIN_PUBLIC ) ;
231
+ if PYTHON_MODE {
232
+ let t = fn0_met (
233
+ poly ( ITERABLE , vec ! [ ty_tp( T . clone( ) ) ] ) ,
234
+ poly ( ITERATOR , vec ! [ ty_tp( T . clone( ) ) ] ) ,
235
+ )
236
+ . quantify ( ) ;
237
+ iterable. register_builtin_erg_decl ( FUNDAMENTAL_ITER , t, Visibility :: BUILTIN_PUBLIC ) ;
238
+ } else {
239
+ let Slf = mono_q ( SELF , subtypeof ( poly ( ITERABLE , vec ! [ ty_tp( T . clone( ) ) ] ) ) ) ;
240
+ let t = fn0_met ( Slf . clone ( ) , proj ( Slf , ITER ) ) . quantify ( ) ;
241
+ iterable. register_builtin_decl (
242
+ FUNC_ITER ,
243
+ t,
244
+ Visibility :: BUILTIN_PUBLIC ,
245
+ Some ( FUNDAMENTAL_ITER ) ,
246
+ ) ;
247
+ iterable. register_builtin_erg_decl ( ITER , Type , Visibility :: BUILTIN_PUBLIC ) ;
248
+ }
239
249
let Slf = poly ( ITERABLE , vec ! [ ty_tp( T . clone( ) ) ] ) ;
240
250
let U = type_q ( TY_U ) ;
241
251
let t_map = fn1_met (
@@ -244,9 +254,10 @@ impl Context {
244
254
poly ( MAP , vec ! [ ty_tp( U . clone( ) ) ] ) ,
245
255
)
246
256
. quantify ( ) ;
247
- iterable. register_builtin_decl (
257
+ iterable. register_builtin_py_impl (
248
258
FUNC_MAP ,
249
259
t_map,
260
+ Mutability :: Immutable ,
250
261
Visibility :: BUILTIN_PUBLIC ,
251
262
Some ( "Function::iterable_map" ) ,
252
263
) ;
@@ -268,9 +279,10 @@ impl Context {
268
279
)
269
280
. quantify ( ) ;
270
281
let t_filter = t_filter. with_default_intersec_index ( 1 ) ;
271
- iterable. register_builtin_decl (
282
+ iterable. register_builtin_py_impl (
272
283
FUNC_FILTER ,
273
284
t_filter,
285
+ Mutability :: Immutable ,
274
286
Visibility :: BUILTIN_PUBLIC ,
275
287
Some ( "Function::iterable_filter" ) ,
276
288
) ;
@@ -279,9 +291,10 @@ impl Context {
279
291
vec ! [ TyParam :: List ( vec![ ty_tp( Nat ) , ty_tp( T . clone( ) ) ] ) ] ,
280
292
) ;
281
293
let t_enumerate = fn0_met ( Slf . clone ( ) , poly ( ITERATOR , vec ! [ ty_tp( ret_t) ] ) ) . quantify ( ) ;
282
- iterable. register_builtin_decl (
294
+ iterable. register_builtin_py_impl (
283
295
FUNC_ENUMERATE ,
284
296
t_enumerate,
297
+ Mutability :: Immutable ,
285
298
Visibility :: BUILTIN_PUBLIC ,
286
299
Some ( "Function::enumerate" ) ,
287
300
) ;
@@ -291,9 +304,10 @@ impl Context {
291
304
poly ( ZIP , vec ! [ ty_tp( T . clone( ) ) , ty_tp( U . clone( ) ) ] ) ,
292
305
)
293
306
. quantify ( ) ;
294
- iterable. register_builtin_decl (
307
+ iterable. register_builtin_py_impl (
295
308
FUNC_ZIP ,
296
309
t_zip,
310
+ Mutability :: Immutable ,
297
311
Visibility :: BUILTIN_PUBLIC ,
298
312
Some ( "Function::zip" ) ,
299
313
) ;
@@ -304,59 +318,67 @@ impl Context {
304
318
T . clone ( ) ,
305
319
)
306
320
. quantify ( ) ;
307
- iterable. register_builtin_decl (
321
+ iterable. register_builtin_py_impl (
308
322
FUNC_REDUCE ,
309
323
t_reduce,
324
+ Mutability :: Immutable ,
310
325
Visibility :: BUILTIN_PUBLIC ,
311
326
Some ( "Function::iterable_reduce" ) ,
312
327
) ;
313
328
let t_nth = fn1_met ( Slf . clone ( ) , Nat , T . clone ( ) ) . quantify ( ) ;
314
- iterable. register_builtin_decl (
329
+ iterable. register_builtin_py_impl (
315
330
FUNC_NTH ,
316
331
t_nth,
332
+ Mutability :: Immutable ,
317
333
Visibility :: BUILTIN_PUBLIC ,
318
334
Some ( "Function::iterable_nth" ) ,
319
335
) ;
320
336
let t_skip = fn1_met ( Slf . clone ( ) , Nat , poly ( ITERATOR , vec ! [ ty_tp( T . clone( ) ) ] ) ) . quantify ( ) ;
321
- iterable. register_builtin_decl (
337
+ iterable. register_builtin_py_impl (
322
338
FUNC_SKIP ,
323
339
t_skip,
340
+ Mutability :: Immutable ,
324
341
Visibility :: BUILTIN_PUBLIC ,
325
342
Some ( "Function::iterable_skip" ) ,
326
343
) ;
327
344
let t_all = fn1_met ( Slf . clone ( ) , func1 ( T . clone ( ) , Bool ) , Bool ) . quantify ( ) ;
328
- iterable. register_builtin_decl (
345
+ iterable. register_builtin_py_impl (
329
346
FUNC_ALL ,
330
347
t_all,
348
+ Mutability :: Immutable ,
331
349
Visibility :: BUILTIN_PUBLIC ,
332
350
Some ( "Function::iterable_all" ) ,
333
351
) ;
334
352
let t_any = fn1_met ( Slf . clone ( ) , func1 ( T . clone ( ) , Bool ) , Bool ) . quantify ( ) ;
335
- iterable. register_builtin_decl (
353
+ iterable. register_builtin_py_impl (
336
354
FUNC_ANY ,
337
355
t_any,
356
+ Mutability :: Immutable ,
338
357
Visibility :: BUILTIN_PUBLIC ,
339
358
Some ( "Function::iterable_any" ) ,
340
359
) ;
341
360
let t_reversed = fn0_met ( Slf . clone ( ) , poly ( ITERATOR , vec ! [ ty_tp( T . clone( ) ) ] ) ) . quantify ( ) ;
342
- iterable. register_builtin_decl (
361
+ iterable. register_builtin_py_impl (
343
362
FUNC_REVERSED ,
344
363
t_reversed,
364
+ Mutability :: Immutable ,
345
365
Visibility :: BUILTIN_PUBLIC ,
346
366
Some ( "Function::reversed" ) ,
347
367
) ;
348
368
let t_position = fn1_met ( Slf . clone ( ) , func1 ( T . clone ( ) , Bool ) , or ( Nat , NoneType ) ) . quantify ( ) ;
349
- iterable. register_builtin_decl (
369
+ iterable. register_builtin_py_impl (
350
370
FUNC_POSITION ,
351
371
t_position,
372
+ Mutability :: Immutable ,
352
373
Visibility :: BUILTIN_PUBLIC ,
353
374
Some ( "Function::iterable_position" ) ,
354
375
) ;
355
376
let t_find =
356
377
fn1_met ( Slf . clone ( ) , func1 ( T . clone ( ) , Bool ) , or ( T . clone ( ) , NoneType ) ) . quantify ( ) ;
357
- iterable. register_builtin_decl (
378
+ iterable. register_builtin_py_impl (
358
379
FUNC_FIND ,
359
380
t_find,
381
+ Mutability :: Immutable ,
360
382
Visibility :: BUILTIN_PUBLIC ,
361
383
Some ( "Function::iterable_find" ) ,
362
384
) ;
@@ -369,16 +391,18 @@ impl Context {
369
391
poly ( ITERATOR , vec ! [ ty_tp( T . clone( ) ) ] ) ,
370
392
)
371
393
. quantify ( ) ;
372
- iterable. register_builtin_decl (
394
+ iterable. register_builtin_py_impl (
373
395
FUNC_CHAIN ,
374
396
t_chain,
397
+ Mutability :: Immutable ,
375
398
Visibility :: BUILTIN_PUBLIC ,
376
399
Some ( "Function::iterable_chain" ) ,
377
400
) ;
378
401
let t_to_list = fn0_met ( Slf . clone ( ) , unknown_len_list_t ( T . clone ( ) ) ) . quantify ( ) ;
379
- iterable. register_builtin_decl (
402
+ iterable. register_builtin_py_impl (
380
403
FUNC_TO_LIST ,
381
404
t_to_list,
405
+ Mutability :: Immutable ,
382
406
Visibility :: BUILTIN_PUBLIC ,
383
407
Some ( "Function::list" ) ,
384
408
) ;
@@ -396,7 +420,7 @@ impl Context {
396
420
) ;
397
421
/* Container */
398
422
let mut container = Self :: builtin_poly_trait ( CONTAINER , vec ! [ PS :: t_nd( TY_T ) ] , 2 ) ;
399
- let op_t = fn1_met ( mono ( CONTAINER ) , T . clone ( ) , Bool ) . quantify ( ) ;
423
+ let op_t = fn1_met ( poly ( CONTAINER , vec ! [ ty_tp ( T . clone ( ) ) ] ) , T . clone ( ) , Bool ) . quantify ( ) ;
400
424
container. register_superclass ( poly ( OUTPUT , vec ! [ ty_tp( T . clone( ) ) ] ) , & output) ;
401
425
container. register_builtin_erg_decl ( FUNDAMENTAL_CONTAINS , op_t, Visibility :: BUILTIN_PUBLIC ) ;
402
426
/* Collection */
0 commit comments